Do not always save executable name in memory in sync package

This commit is contained in:
2024-07-09 16:04:03 -04:00
parent 10d5dea6c3
commit 98308782a9
5 changed files with 14 additions and 23 deletions
-9
View File
@@ -1,9 +0,0 @@
//go:build !windows
package sync
import (
"os"
)
var vanityEXE = os.Args[0]
-10
View File
@@ -1,10 +0,0 @@
//go:build windows
package sync
import (
"os"
"strings"
)
var vanityEXE = os.Args[0][strings.LastIndex(os.Args[0], "\\")+1:]
+2 -2
View File
@@ -26,7 +26,7 @@ func getSSHClient(manualSync bool) (*ssh.Client, string, bool) {
var sshUserConfig []string var sshUserConfig []string
var missingValueError string var missingValueError string
if manualSync { if manualSync {
missingValueError = "SSH settings not configured - run \"" + vanityEXE + " init\" to configure" missingValueError = joinErrorWithEXE("SSH settings not configured - run \"", " init\" to configure")
} else { } else {
missingValueError = "0" missingValueError = "0"
} }
@@ -135,7 +135,7 @@ func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []str
clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices") clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
if len(clientDeviceID) == 0 { if len(clientDeviceID) == 0 {
if manualSync { if manualSync {
fmt.Println(backend.AnsiError + "Sync failed - No device ID found; run \"" + vanityEXE + " init\" to generate a device ID" + backend.AnsiReset) fmt.Println(joinErrorWithEXE("Sync failed - No device ID found; run \"", " init\" to generate a device ID"))
os.Exit(1) os.Exit(1)
} else { } else {
backend.Exit(0) // exit silently if the sync job was called automatically, as the user may just be in offline mode backend.Exit(0) // exit silently if the sync job was called automatically, as the user may just be in offline mode
+6 -1
View File
@@ -24,7 +24,7 @@ func WalkEntryDir() ([]string, []string) {
// check for errors encountered while walking directory // check for errors encountered while walking directory
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+vanityEXE, "init"+"\" to create it"+backend.AnsiReset) fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+os.Args[0], "init"+"\" to create it"+backend.AnsiReset)
} else { } else {
// otherwise, print the source of the error // otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset) fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
@@ -47,3 +47,8 @@ func WalkEntryDir() ([]string, []string) {
return fileList, dirList return fileList, dirList
} }
// joinErrorWithEXE joins and returns the two strings it is provided (in error format) with the executable name inserted between them
func joinErrorWithEXE(firstHalf, secondHalf string) string {
return backend.AnsiError + firstHalf + os.Args[0] + secondHalf + backend.AnsiReset
}
+6 -1
View File
@@ -25,7 +25,7 @@ func WalkEntryDir() ([]string, []string) {
// check for errors encountered while walking directory // check for errors encountered while walking directory
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+vanityEXE, "init"+"\" to create it"+backend.AnsiReset) fmt.Println(joinErrorWithEXE("The entry directory does not exist - run \"", " init"+"\" to create it"))
} else { } else {
// otherwise, print the source of the error // otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset) fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
@@ -48,3 +48,8 @@ func WalkEntryDir() ([]string, []string) {
return fileList, dirList return fileList, dirList
} }
// joinErrorWithEXE joins and returns the two strings it is provided (in error format) with the executable name inserted between them
func joinErrorWithEXE(firstHalf, secondHalf string) string {
return backend.AnsiError + firstHalf + os.Args[0][strings.LastIndex(os.Args[0], "\\")+1:] + secondHalf + backend.AnsiReset
}