diff --git a/libmuttonserver.go b/libmuttonserver.go index 06dcb92..cd4da7b 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -119,10 +119,10 @@ func main() { fmt.Printf("{\"errMsg\":\"%s\"}", err.Error()) return } - for _, deletion := range deletionsList { - affectedIDVanityPath := strings.Split(deletion.Name(), global.FSSpace) + for i := range deletionsList { + affectedIDVanityPath := strings.Split(deletionsList[i].Name(), global.FSSpace) if affectedIDVanityPath[0] == *registerReq.OldDeviceID { - if err = os.Rename(deletionsDirRoot+deletion.Name(), deletionsDirRoot+registerReq.NewDeviceID+global.FSSpace+affectedIDVanityPath[1]+global.FSSpace+affectedIDVanityPath[2]); err != nil { + if err = os.Rename(deletionsDirRoot+deletionsList[i].Name(), deletionsDirRoot+registerReq.NewDeviceID+global.FSSpace+affectedIDVanityPath[1]+global.FSSpace+affectedIDVanityPath[2]); err != nil { fmt.Printf("{\"errMsg\":\"%s\"}", err.Error()) return } diff --git a/syncclient/client.go b/syncclient/client.go index c2d5482..d188ce3 100644 --- a/syncclient/client.go +++ b/syncclient/client.go @@ -364,16 +364,16 @@ func syncLists(sshClient *ssh.Client, sshEntryRoot, sshAgeDir string, sshIsWindo // deletionSync removes entries from the client that have been deleted on the server (multi-client deletion). func deletionSync(deletions []synccommon.Deletion) error { var entryDeleted bool - for _, deletion := range deletions { - if !deletion.IsAgeFile { + for i := range deletions { + if !deletions[i].IsAgeFile { entryDeleted = true // set a flag to indicate that at least one entry has been deleted (used to determine whether to print a gap between deletion and other messages) - fmt.Println(synccommon.AnsiDelete+deletion.VanityPath+back.AnsiReset, "has been sheared, removing locally (if it exists)") + fmt.Println(synccommon.AnsiDelete+deletions[i].VanityPath+back.AnsiReset, "has been sheared, removing locally (if it exists)") } - if err := os.RemoveAll(global.GetRealPath(deletion.VanityPath)); err != nil { - if !deletion.IsAgeFile { - return errors.New("unable to shear " + deletion.VanityPath + " locally: " + err.Error()) + if err := os.RemoveAll(global.GetRealPath(deletions[i].VanityPath)); err != nil { + if !deletions[i].IsAgeFile { + return errors.New("unable to shear " + deletions[i].VanityPath + " locally: " + err.Error()) } - return errors.New("unable to shear age file for " + deletion.VanityPath + " locally: " + err.Error()) + return errors.New("unable to shear age file for " + deletions[i].VanityPath + " locally: " + err.Error()) } } if entryDeleted { @@ -429,9 +429,9 @@ func RunJob() (*syncListsT, error) { } // add deletions info to sync lists - for _, deletion := range deletions { - if !deletion.IsAgeFile { - syncListsV.Delete = append(syncListsV.Delete, deletion.VanityPath) + for i := range deletions { + if !deletions[i].IsAgeFile { + syncListsV.Delete = append(syncListsV.Delete, deletions[i].VanityPath) } } diff --git a/synccommon/common.go b/synccommon/common.go index 63dfc06..eefed5c 100644 --- a/synccommon/common.go +++ b/synccommon/common.go @@ -95,17 +95,17 @@ func ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (strin // add the sheared vanityPath to the deletions list (if running on a server) if onServer { - for _, device := range deviceIDList { - if device.Name() != clientDeviceID { + for i := range deviceIDList { + if deviceIDList[i].Name() != clientDeviceID { if !onlyShearAgeFile { - f, err := os.OpenFile(global.CfgDir+global.PathSeparator+"deletions"+global.PathSeparator+device.Name()+global.FSSpace+"entry"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600) + f, err := os.OpenFile(global.CfgDir+global.PathSeparator+"deletions"+global.PathSeparator+deviceIDList[i].Name()+global.FSSpace+"entry"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600) if err != nil { // failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical) return "", false, err } _ = f.Close() // error ignored; if the file could be created, it can probably be closed } - f, err := os.OpenFile(global.CfgDir+global.PathSeparator+"deletions"+global.PathSeparator+device.Name()+global.FSSpace+"age"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600) + f, err := os.OpenFile(global.CfgDir+global.PathSeparator+"deletions"+global.PathSeparator+deviceIDList[i].Name()+global.FSSpace+"age"+global.FSSpace+strings.ReplaceAll(vanityPath, "/", global.FSPath), os.O_CREATE|os.O_WRONLY, 0600) if err != nil { // failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical) return "", false, err diff --git a/syncserver/server.go b/syncserver/server.go index 63c99a3..571eb2f 100644 --- a/syncserver/server.go +++ b/syncserver/server.go @@ -31,9 +31,9 @@ func GetRemoteDataFromServer(clientDeviceID string) { //// server time fetchResp.ServerTime = time.Now().Unix() //// deletions - for _, deletion := range deletionsList { + for i := range deletionsList { // perform deletion if it is relevant to the current client device - affectedIDVanityPath := strings.Split(deletion.Name(), global.FSSpace) + affectedIDVanityPath := strings.Split(deletionsList[i].Name(), global.FSSpace) if affectedIDVanityPath[0] == clientDeviceID { var isAgeFile bool if affectedIDVanityPath[1] == "age" { @@ -42,7 +42,7 @@ func GetRemoteDataFromServer(clientDeviceID string) { fetchResp.Deletions = append(fetchResp.Deletions, synccommon.Deletion{VanityPath: strings.ReplaceAll(affectedIDVanityPath[2], global.FSPath, "/"), IsAgeFile: isAgeFile}) // assume successful client deletion and remove deletions file (if assumption is somehow false, worst case scenario is that the client will re-upload the deleted entry) - if err = os.RemoveAll(global.CfgDir + global.PathSeparator + "deletions" + global.PathSeparator + deletion.Name()); err != nil { + if err = os.RemoveAll(global.CfgDir + global.PathSeparator + "deletions" + global.PathSeparator + deletionsList[i].Name()); err != nil { fmt.Printf("{\"errMsg\":\"%s\"}", err.Error()) return }