mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Parse deletions per-deviceID
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ func main() {
|
||||
switch args[1] {
|
||||
case "fetch":
|
||||
// print all information needed for syncing to stdout for interpretation by the client
|
||||
sync.GetRemoteDataFromServer()
|
||||
sync.GetRemoteDataFromServer(args[2])
|
||||
case "shear":
|
||||
// shear an entry from the server and add it to the deletions directory
|
||||
deviceIDTargetLocation := strings.Split(args[2], "\x1d")
|
||||
|
||||
+2
-1
@@ -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
@@ -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
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user