Parse deletions per-deviceID

This commit is contained in:
2024-05-16 17:46:03 -04:00
parent cb9d082232
commit e80253ef19
3 changed files with 13 additions and 4 deletions
+2 -1
View File
@@ -102,7 +102,8 @@ func GetSSHOutput(cmd string, manualSync bool) string {
// getRemoteDataFromClient returns a map of remote entries to their modification times, a list of remote folders, and a list of queued deletions
func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []string) {
// get remote output over SSH
output := GetSSHOutput("libmuttonserver fetch", manualSync)
clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
output := GetSSHOutput("libmuttonserver fetch "+clientDeviceID[0].Name(), manualSync)
// split output into slice based on occurrences of "\x1d"
outputSlice := strings.Split(output, "\x1d")
+1 -1
View File
@@ -62,7 +62,7 @@ func getModTimes(entryList []string) []int64 {
// if running on the server, it will also add the target to the deletions list
// if running on the client, it will call the server to add the target to the deletions list
func Shear(targetLocationIncomplete string, deviceID string) {
// get the full targetLocation path and remove the target
// get the full targetLocation path and remove the target TODO move so that the target is not removed if the server fails to add it to the deletions list
targetLocationComplete := backend.TargetLocationFormat(targetLocationIncomplete[1:])
backend.TargetIsFile(targetLocationComplete, true, 0) // needed because os.RemoveAll does not return an error if target does not exist
err := os.RemoveAll(targetLocationComplete)
+10 -2
View File
@@ -4,12 +4,13 @@ import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"os"
"strings"
)
// GetRemoteDataFromServer prints to stdout the remote entries, mod times, folders, and deletions
// lists in output are separated by "\x1d"
// output is meant to be captured over SSH for interpretation by the client
func GetRemoteDataFromServer() {
func GetRemoteDataFromServer(clientDeviceID string) {
entryList, dirList := WalkEntryDir()
modList := getModTimes(entryList)
deletionsList, err := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "deletions")
@@ -33,6 +34,13 @@ func GetRemoteDataFromServer() {
}
fmt.Print("\x1d")
for _, deletion := range deletionsList {
fmt.Print("\x1f" + deletion.Name())
// print deletion if it is relevant to the current client device
affectedIDTargetLocationIncomplete := strings.Split(deletion.Name(), "\x1d")
if affectedIDTargetLocationIncomplete[0] == clientDeviceID {
fmt.Print("\x1f" + strings.ReplaceAll(affectedIDTargetLocationIncomplete[1], "\x1e", backend.PathSeparator))
// 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)
os.Remove(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + deletion.Name())
}
}
}