Bump go-boilerplate; make error codes sequential

This commit is contained in:
2025-06-01 14:17:51 -04:00
parent 2e3be57e3e
commit 5f8789a0f0
12 changed files with 26 additions and 21 deletions
+4 -1
View File
@@ -15,7 +15,10 @@ import (
// CopyArgument copies a field from an entry to the clipboard. // CopyArgument copies a field from an entry to the clipboard.
func CopyArgument(targetLocation string, field int) error { func CopyArgument(targetLocation string, field int) error {
if isFile, _ := back.TargetIsFile(targetLocation, true, 2); isFile { if isFile, _, err := back.TargetIsFile(targetLocation, true, 2); isFile {
if err != nil {
return err
}
decryptedEntry, err := crypt.DecryptFileToSlice(targetLocation) decryptedEntry, err := crypt.DecryptFileToSlice(targetLocation)
if err != nil { if err != nil {
+1 -1
View File
@@ -21,7 +21,7 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][
// ensure ssh key file exists // ensure ssh key file exists
fallbackSSHKey := back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "id_ed25519" fallbackSSHKey := back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "id_ed25519"
sshKeyPath := cmp.Or(back.ExpandPathWithHome(inputCB(back.AnsiBold+"Note:"+back.AnsiReset+" Only key-based authentication is supported (keys may optionally be passphrase-protected).\n The remote server must already be in your ~"+global.PathSeparator+".ssh"+global.PathSeparator+"known_hosts file.\n\nSSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey) sshKeyPath := cmp.Or(back.ExpandPathWithHome(inputCB(back.AnsiBold+"Note:"+back.AnsiReset+" Only key-based authentication is supported (keys may optionally be passphrase-protected).\n The remote server must already be in your ~"+global.PathSeparator+".ssh"+global.PathSeparator+"known_hosts file.\n\nSSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey)
sshKeyIsFile, _ := back.TargetIsFile(sshKeyPath, false, 0) sshKeyIsFile, _, _ := back.TargetIsFile(sshKeyPath, false, 0) // error is ignored because errorOnFail is false
if !sshKeyIsFile { if !sshKeyIsFile {
return errors.New("SSH identity file not found: " + sshKeyPath) return errors.New("SSH identity file not found: " + sshKeyPath)
} }
+2 -2
View File
@@ -13,7 +13,7 @@ import (
// For non-interactive CLI implementations, an entirely separate process is created for this purpose. // For non-interactive CLI implementations, an entirely separate process is created for this purpose.
func LaunchClipClearProcess(copySubject string) { func LaunchClipClearProcess(copySubject string) {
cmd := exec.Command(os.Args[0], "clipclear") cmd := exec.Command(os.Args[0], "clipclear")
back.WriteToStdin(cmd, copySubject) _ = back.WriteToStdin(cmd, copySubject)
cmd.Start() _ = cmd.Start()
os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations
} }
+1 -1
View File
@@ -14,7 +14,7 @@ import (
// For non-interactive CLI implementations, an entirely separate process is created for this purpose. // For non-interactive CLI implementations, an entirely separate process is created for this purpose.
func LaunchClipClearProcess(copySubject string, isWayland bool) { func LaunchClipClearProcess(copySubject string, isWayland bool) {
cmd := exec.Command(os.Args[0], "clipclear", strconv.FormatBool(isWayland)) cmd := exec.Command(os.Args[0], "clipclear", strconv.FormatBool(isWayland))
back.WriteToStdin(cmd, copySubject) _ = back.WriteToStdin(cmd, copySubject)
_ = cmd.Start() _ = cmd.Start()
os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations
} }
+2 -2
View File
@@ -156,13 +156,13 @@ func ClampTrailingWhitespace(note []string) {
// Returns: statusCode (0 = success, 1 = target location already exists, 2 = containing directory is invalid). // Returns: statusCode (0 = success, 1 = target location already exists, 2 = containing directory is invalid).
func EntryAddPrecheck(targetLocation string) (uint8, error) { func EntryAddPrecheck(targetLocation string) (uint8, error) {
// ensure target location does not already exist // ensure target location does not already exist
_, isAccessible := back.TargetIsFile(targetLocation, false, 0) _, isAccessible, _ := back.TargetIsFile(targetLocation, false, 0) // error is ignored because errorOnFail is false
if isAccessible { if isAccessible {
return 1, errors.New("target location already exists") return 1, errors.New("target location already exists")
} }
// ensure target containing directory exists and is a directory (not a file) // ensure target containing directory exists and is a directory (not a file)
containingDir := targetLocation[:strings.LastIndex(targetLocation, global.PathSeparator)] containingDir := targetLocation[:strings.LastIndex(targetLocation, global.PathSeparator)]
isFile, isAccessible := back.TargetIsFile(containingDir, false, 1) isFile, isAccessible, _ := back.TargetIsFile(containingDir, false, 1) // error is ignored because errorOnFail is false
if isFile || !isAccessible { if isFile || !isAccessible {
return 2, errors.New("\"" + containingDir + "\" is not a valid containing directory") return 2, errors.New("\"" + containingDir + "\" is not a valid containing directory")
} }
+4 -6
View File
@@ -13,10 +13,8 @@ const (
FSPath = "\u259e" // ▞ Path separator FSPath = "\u259e" // ▞ Path separator
FSMisc = "\u259f" // ▟ Misc. field separator (if \u259d is already used) FSMisc = "\u259f" // ▟ Misc. field separator (if \u259d is already used)
ErrorSyncProcess = 103 ErrorSyncProcess = 104
ErrorServerConnection = 104 ErrorDecryption = 105
ErrorTargetExists = 106 ErrorEncryption = 106
ErrorDecryption = 108 ErrorClipboard = 107
ErrorEncryption = 109
ErrorClipboard = 110
) )
+1 -1
View File
@@ -24,7 +24,7 @@ func DirInit(preserveOldConfigDir bool) (string, error) {
// remove existing config directory (if it exists and not in append mode) // remove existing config directory (if it exists and not in append mode)
if !preserveOldConfigDir { if !preserveOldConfigDir {
_, isAccessible := back.TargetIsFile(ConfigDir, false, 1) _, isAccessible, _ := back.TargetIsFile(ConfigDir, false, 1) // error is ignored because errorOnFail is false
if isAccessible { if isAccessible {
err = os.RemoveAll(ConfigDir) err = os.RemoveAll(ConfigDir)
if err != nil { if err != nil {
+1 -1
View File
@@ -5,7 +5,7 @@ go 1.24.3
require ( require (
github.com/pkg/sftp v1.13.9 github.com/pkg/sftp v1.13.9
github.com/pquerna/otp v1.5.0 github.com/pquerna/otp v1.5.0
github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b github.com/rwinkhart/go-boilerplate v0.0.0-20250601181619-e38a47784de0
github.com/rwinkhart/rcw v0.2.0 github.com/rwinkhart/rcw v0.2.0
golang.design/x/clipboard v0.7.0 // only for Android builds golang.design/x/clipboard v0.7.0 // only for Android builds
golang.org/x/crypto v0.38.0 golang.org/x/crypto v0.38.0
+2 -2
View File
@@ -13,8 +13,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs= github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b h1:ENgsUlCmYktd1eauEkjW6Fu8rgZzyGOS/m/6jc968xI= github.com/rwinkhart/go-boilerplate v0.0.0-20250601181619-e38a47784de0 h1:Zuwn0er30tMYrBXD1n4nM3mkGhrLFAdn3sZyMHkxx2I=
github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY= github.com/rwinkhart/go-boilerplate v0.0.0-20250601181619-e38a47784de0/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY=
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE=
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/rwinkhart/peercred-mini v0.1.0 h1:TiS6u8cEWzW55S9X4iVpU72Iuy/NG6rMUJMtUEVEFLw= github.com/rwinkhart/peercred-mini v0.1.0 h1:TiS6u8cEWzW55S9X4iVpU72Iuy/NG6rMUJMtUEVEFLw=
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/rwinkhart/go-boilerplate/back" "github.com/rwinkhart/go-boilerplate/back"
"github.com/rwinkhart/go-boilerplate/other"
"github.com/rwinkhart/libmutton/global" "github.com/rwinkhart/libmutton/global"
"github.com/rwinkhart/libmutton/synccommon" "github.com/rwinkhart/libmutton/synccommon"
"github.com/rwinkhart/libmutton/syncserver" "github.com/rwinkhart/libmutton/syncserver"
@@ -70,7 +71,7 @@ func main() {
// create the necessary directories for libmuttonserver to function // create the necessary directories for libmuttonserver to function
_, err := global.DirInit(false) _, err := global.DirInit(false)
if err != nil { if err != nil {
back.PrintError("Failed to initialize libmuttonserver directories: "+err.Error(), back.ErrorWrite, true) other.PrintError("Failed to initialize libmuttonserver directories: "+err.Error(), back.ErrorWrite, true)
} }
_ = os.MkdirAll(global.ConfigDir+global.PathSeparator+"deletions", 0700) // error ignored; failure would have occurred by this point in core.DirInit _ = os.MkdirAll(global.ConfigDir+global.PathSeparator+"deletions", 0700) // error ignored; failure would have occurred by this point in core.DirInit
fmt.Println("libmuttonserver directories initialized") fmt.Println("libmuttonserver directories initialized")
+1 -1
View File
@@ -417,7 +417,7 @@ func folderSync(folders []string) error {
folderFullPath := global.TargetLocationFormat(folder) folderFullPath := global.TargetLocationFormat(folder)
// check if folder already exists // check if folder already exists
isFile, isAccessible := back.TargetIsFile(folderFullPath, false, 1) isFile, isAccessible, _ := back.TargetIsFile(folderFullPath, false, 1) // error is ignored because errorOnFail is false
if !isFile && !isAccessible { if !isFile && !isAccessible {
err := os.MkdirAll(folderFullPath, 0700) err := os.MkdirAll(folderFullPath, 0700)
+5 -2
View File
@@ -66,7 +66,10 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) (string, bool,
targetLocationComplete := global.TargetLocationFormat(targetLocationIncomplete) targetLocationComplete := global.TargetLocationFormat(targetLocationIncomplete)
var isFile bool var isFile bool
if !onServer { // error if target does not exist on client, needed because os.RemoveAll does not return an error if target does not exist if !onServer { // error if target does not exist on client, needed because os.RemoveAll does not return an error if target does not exist
isFile, _ = back.TargetIsFile(targetLocationComplete, true, 0) isFile, _, err = back.TargetIsFile(targetLocationComplete, true, 0)
if err != nil {
return "", false, err
}
} }
err = os.RemoveAll(targetLocationComplete) err = os.RemoveAll(targetLocationComplete)
if err != nil { if err != nil {
@@ -93,7 +96,7 @@ func RenameLocal(oldLocationIncomplete, newLocationIncomplete string, verifyOldL
} }
// ensure newLocation does not exist // ensure newLocation does not exist
_, isAccessible := back.TargetIsFile(newLocation, false, 0) _, isAccessible, _ := back.TargetIsFile(newLocation, false, 0) // error is ignored because errorOnFail is false
if isAccessible { if isAccessible {
return errors.New("target already exists: " + newLocation) return errors.New("target already exists: " + newLocation)
} }