diff --git a/src/backend/edit.go b/src/backend/edit.go index 5e79680..09e3155 100644 --- a/src/backend/edit.go +++ b/src/backend/edit.go @@ -36,7 +36,7 @@ func Rename(oldLocation string, newLocation string) { fmt.Println(AnsiError + "Failed to rename - does the target containing directory exists?" + AnsiReset) } - // TODO If in online mode, check if oldLocation is a directory and rename it on the server + // TODO If in online mode, rename oldLocation to newLocation on the server os.Exit(0) } diff --git a/src/cli/init.go b/src/cli/init.go index 3477689..b1508c9 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/sync" - "math/rand" "os" ) @@ -40,12 +39,8 @@ func TempInitCli() { // write config file backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID, "sshUser": sshUser, "sshIP": sshIP, "sshPort": sshPort, "sshIdentity": sshIdentity}) - // client device ID (perform after writing config files, as sync.GetSSHOutput must be able to read it) TODO move to backend - deviceIDPrefix, _ := os.Hostname() - deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, false, 0) // TODO consider using complex string generator and removing unsafe characters manually - deviceID := deviceIDPrefix + "-" + deviceIDSuffix - os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server) - sync.GetSSHOutput("libmuttonserver register "+deviceID, false) // register device ID with server + // generate device ID + sync.DeviceIDGen() } else { // write config file backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID}) diff --git a/src/sync/client.go b/src/sync/client.go index 995af1e..5d0f906 100644 --- a/src/sync/client.go +++ b/src/sync/client.go @@ -187,7 +187,7 @@ func deletionSync(deletions []string) { } // folderSync creates folders on the client (from the given list of folder names) -func folderSync(folders []string) { // TODO also add folders on server when they are created from the client +func folderSync(folders []string) { for _, folder := range folders { // check if folder already exists isFile, isAccessible := backend.TargetIsFile(backend.EntryRoot+folder, false, 1) diff --git a/src/sync/init.go b/src/sync/init.go new file mode 100644 index 0000000..49a9bf4 --- /dev/null +++ b/src/sync/init.go @@ -0,0 +1,17 @@ +package sync + +import ( + "github.com/rwinkhart/MUTN/src/backend" + "math/rand" + "os" +) + +// DeviceIDGen generates a new client device ID and registers it with the server +// device IDs are only needed for online synchronization +func DeviceIDGen() { + deviceIDPrefix, _ := os.Hostname() + deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, false, 0) // TODO consider using complex string generator and removing unsafe characters manually + deviceID := deviceIDPrefix + "-" + deviceIDSuffix + os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server) + GetSSHOutput("libmuttonserver register "+deviceID, false) // register device ID with server +}