sshfs: implement rm via ssh
this is similar to change we did for cp -r . sshfs is often flaky with lots of concurrent operations
This commit is contained in:
@@ -170,7 +170,7 @@ async function copy(apiConfig, oldFilePath, newFilePath, progressCallback) {
|
||||
const [remoteCopyError] = await safe(shell.spawn('ssh', sshArgs, { shell: true }));
|
||||
if (!remoteCopyError) return;
|
||||
if (remoteCopyError.code === 255) throw new BoxError(BoxError.EXTERNAL_ERROR, `SSH connection error: ${remoteCopyError.message}`); // do not attempt fallback copy for ssh errors
|
||||
debug('SSH remote copy failed, trying ssfs copy'); // this can happen for sshfs mounted windows server
|
||||
debug('SSH remote copy failed, trying sshfs copy'); // this can happen for sshfs mounted windows server
|
||||
}
|
||||
|
||||
const [copyError] = await safe(shell.spawn('cp', [ cpOptions, oldFilePath, newFilePath ], {}));
|
||||
@@ -198,6 +198,17 @@ async function removeDir(apiConfig, pathPrefix, progressCallback) {
|
||||
|
||||
progressCallback({ message: `Removing directory ${pathPrefix}` });
|
||||
|
||||
if (apiConfig.provider === PROVIDER_SSHFS) {
|
||||
const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${apiConfig.mountOptions.host}`);
|
||||
|
||||
const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', apiConfig.mountOptions.port, `${apiConfig.mountOptions.user}@${apiConfig.mountOptions.host}` ];
|
||||
const sshArgs = sshOptions.concat([ 'rm', '-rf', pathPrefix.replace('/mnt/cloudronbackup/', '') ]);
|
||||
const [remoteRmError] = await safe(shell.spawn('ssh', sshArgs, { shell: true }));
|
||||
if (!remoteRmError) return;
|
||||
if (remoteRmError.code === 255) throw new BoxError(BoxError.EXTERNAL_ERROR, `SSH connection error: ${remoteRmError.message}`); // do not attempt fallback copy for ssh errors
|
||||
debug('SSH remote rm failed, trying sshfs rm'); // this can happen for sshfs mounted windows server
|
||||
}
|
||||
|
||||
const [error] = await safe(shell.spawn('rm', [ '-rf', pathPrefix ], {}));
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user