mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Fix init deleting device ID immediately after generating it; fix sync failure for non-manual syncs
This commit is contained in:
+13
-13
@@ -10,12 +10,10 @@ import (
|
||||
)
|
||||
|
||||
// TempInit ensures libmutton directories exist and writes the libmutton configuration file
|
||||
func TempInit(configFileMap map[string]string) {
|
||||
// TODO if run in append mode, extend old config file with new values, rather than creating from scratch
|
||||
func TempInit(configFileMap map[string]string, append bool) {
|
||||
// create EntryRoot and ConfigDir
|
||||
DirInit()
|
||||
|
||||
// remove existing config file
|
||||
removeFile(ConfigPath)
|
||||
DirInit(append)
|
||||
|
||||
if configFileMap["textEditor"] == "" {
|
||||
configFileMap["textEditor"] = textEditorFallback()
|
||||
@@ -68,7 +66,7 @@ func GpgKeyGen() string {
|
||||
}
|
||||
|
||||
// DirInit creates the libmutton directories
|
||||
func DirInit() {
|
||||
func DirInit(preserveOldConfigDir bool) {
|
||||
// create EntryRoot
|
||||
err := os.MkdirAll(EntryRoot, 0700)
|
||||
if err != nil {
|
||||
@@ -76,14 +74,16 @@ func DirInit() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// remove existing config directory (if it exists)
|
||||
_, isAccessible := TargetIsFile(ConfigDir, false, 1)
|
||||
if isAccessible {
|
||||
err = os.RemoveAll(ConfigDir)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to remove existing config directory: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
// remove existing config directory (if it exists and not in append mode)
|
||||
if !preserveOldConfigDir {
|
||||
_, isAccessible := TargetIsFile(ConfigDir, false, 1)
|
||||
if isAccessible {
|
||||
err = os.RemoveAll(ConfigDir)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to remove existing config directory: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -24,11 +24,13 @@ const (
|
||||
func getSSHClient(manualSync bool) (*ssh.Client, string, bool) {
|
||||
// get SSH config info, exit if not configured (displaying an error if the sync job was called manually)
|
||||
var sshUserConfig []string
|
||||
var missingValueError string
|
||||
if manualSync {
|
||||
sshUserConfig = backend.ReadConfig([]string{"sshUser", "sshIP", "sshPort", "sshKey", "sshKeyProtected", "sshEntryRoot", "sshIsWindows"}, "SSH settings not configured - run \"mutn init\" to configure")
|
||||
missingValueError = "SSH settings not configured - run \"mutn init\" to configure"
|
||||
} else {
|
||||
sshUserConfig = backend.ReadConfig([]string{"sshUser", "sshIP", "sshPort", "sshKey", "sshKeyProtected"}, "0")
|
||||
missingValueError = "0"
|
||||
}
|
||||
sshUserConfig = backend.ReadConfig([]string{"sshUser", "sshIP", "sshPort", "sshKey", "sshKeyProtected", "sshEntryRoot", "sshIsWindows"}, missingValueError)
|
||||
|
||||
var user, ip, port, keyFile, keyFileProtected, entryRoot string
|
||||
var isWindows bool
|
||||
@@ -299,7 +301,7 @@ func sftpSync(downloadList, uploadList []string, manualSync bool) {
|
||||
var remoteFile *sftp.File
|
||||
remoteFile, err = sftpClient.Create(remoteEntryFullPath)
|
||||
if err != nil {
|
||||
fmt.Println(backend.AnsiError+"Sync failed - Unable to create remote file:", err.Error()+backend.AnsiReset)
|
||||
fmt.Println(backend.AnsiError+"Sync failed - Unable to create remote file ("+remoteEntryFullPath+"):", err.Error()+backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user