Re-implement age data upload via SFTP (download will continue to use new method)

This commit is contained in:
2026-01-08 20:39:44 -05:00
parent 07571a698d
commit d0e8640ce6
6 changed files with 52 additions and 30 deletions
+13 -13
View File
@@ -29,7 +29,7 @@ func ShearRemote(vanityPath string, onlyShearAgeFile bool) error {
var modifier string
var output []byte
sshClient, offlineMode, _, _, err := GetSSHClient()
sshClient, offlineMode, _, _, _, err := GetSSHClient()
if offlineMode {
goto end
}
@@ -88,7 +88,7 @@ func RenameRemote(oldVanityPath, newVanityPath string) error {
// create an SSH client
var output []byte
sshClient, offlineMode, _, _, err := GetSSHClient()
sshClient, offlineMode, _, _, _, err := GetSSHClient()
if offlineMode {
goto end
}
@@ -131,7 +131,7 @@ func AddFolderRemote(vanityPath string) error {
// create an SSH client
var output []byte
sshClient, offlineMode, _, _, err := GetSSHClient()
sshClient, offlineMode, _, _, _, err := GetSSHClient()
if offlineMode {
goto end
}
@@ -163,8 +163,8 @@ end:
// Device IDs are only needed for online synchronization.
// Device IDs are guaranteed unique as the current UNIX time is appended to them.
// Leave prefix empty to use the current hostname as the prefix.
// Returns: the remote EntryRoot and OS type indicator.
func GenDeviceID(oldDeviceID, prefix string) (string, bool, error) {
// Returns: the remote EntryRoot, the remote AgeDir, and OS type indicator.
func GenDeviceID(oldDeviceID, prefix string) (string, string, bool, error) {
// generate new device ID
if prefix == "" {
prefix, _ = os.Hostname()
@@ -176,7 +176,7 @@ func GenDeviceID(oldDeviceID, prefix string) (string, bool, error) {
oldDeviceIDPath := global.CfgDir + global.PathSeparator + "devices" + global.PathSeparator + oldDeviceID
f, err := os.OpenFile(newDeviceIDPath, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", false, errors.New("unable to create local device ID file: " + err.Error())
return "", "", false, errors.New("unable to create local device ID file: " + err.Error())
}
_ = f.Close() // error ignored; if the file could be created, it can probably be closed
@@ -195,32 +195,32 @@ func GenDeviceID(oldDeviceID, prefix string) (string, bool, error) {
// register new device ID with server and fetch remote EntryRoot and OS type
// also removes the old device ID file (remotely)
// if registration fails, remove the new device ID file locally and return before removing the old one
sshClient, _, _, _, err := GetSSHClient()
sshClient, _, _, _, _, err := GetSSHClient()
if err != nil {
cleanupOnFail()
return "", false, errors.New("unable to connect to SSH client: " + err.Error())
return "", "", false, errors.New("unable to connect to SSH client: " + err.Error())
}
output, err := GetSSHOutput(sshClient, "libmuttonserver register", newDeviceID+"\n"+oldDeviceID)
if err != nil {
cleanupOnFail()
return "", false, errors.New("unable to register device ID with server: " + err.Error())
return "", "", false, errors.New("unable to register device ID with server: " + err.Error())
}
var registerResp synccommon.RegisterResp
if err = json.Unmarshal(output, &registerResp); err != nil {
cleanupOnFail()
return "", false, errors.New("unable to unmarshal server register response: " + err.Error())
return "", "", false, errors.New("unable to unmarshal server register response: " + err.Error())
}
if registerResp.ErrMsg != nil {
cleanupOnFail()
return "", false, errors.New("unable to complete register; server-side error occurred: " + strings.ReplaceAll(*registerResp.ErrMsg, global.FSSpace, "\n"))
return "", "", false, errors.New("unable to complete register; server-side error occurred: " + strings.ReplaceAll(*registerResp.ErrMsg, global.FSSpace, "\n"))
}
_ = sshClient.Close() // ignore error; non-critical/unlikely/not much could be done about it
// remove old device ID file (locally; may not exist)
if err = os.RemoveAll(oldDeviceIDPath); err != nil {
cleanupOnFail()
return "", false, errors.New("unable to remove old device ID file (locally): " + err.Error())
return "", "", false, errors.New("unable to remove old device ID file (locally): " + err.Error())
}
return registerResp.EntryRoot, registerResp.IsWindows, nil
return registerResp.EntryRoot, registerResp.AgeDir, registerResp.IsWindows, nil
}