From 349cd49e4d0bc52d326515c0789e1f8944cfdc68 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Wed, 5 Jun 2024 18:29:38 -0400 Subject: [PATCH] Handle error for failing to create local device ID file --- src/sync/init.go | 6 +++++- src/sync/server.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sync/init.go b/src/sync/init.go index ccfe521..7efbbe9 100644 --- a/src/sync/init.go +++ b/src/sync/init.go @@ -1,6 +1,7 @@ package sync import ( + "fmt" "github.com/rwinkhart/MUTN/src/backend" "math/rand" "os" @@ -14,7 +15,10 @@ func DeviceIDGen() (string, string) { 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) + _, err := os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server) + if err != nil { + fmt.Println(backend.AnsiError + "Failed to create local device ID file: " + err.Error() + backend.AnsiReset) + } // register device ID with server and fetch remote EntryRoot and OS type //manualSync is true so the user is alerted if device ID registration fails diff --git a/src/sync/server.go b/src/sync/server.go index 5f31e0f..b477181 100644 --- a/src/sync/server.go +++ b/src/sync/server.go @@ -48,7 +48,7 @@ func GetRemoteDataFromServer(clientDeviceID string) { fmt.Print("\x1f" + strings.ReplaceAll(affectedIDTargetLocationIncomplete[1], "\x1d", "/")) // 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()) + _ = os.Remove(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + deletion.Name()) // error ignored; function not run from a user-facing argument and thus the error would not be visible } } }