diff --git a/CHANGES b/CHANGES index 8102ee0c2..174eeb06c 100644 --- a/CHANGES +++ b/CHANGES @@ -2936,4 +2936,4 @@ * token: access can by restricted by ip range(s) * sendmail: requiresValidCertificate option for using mail server domain * mail: update haraka to 3.1.0 - +* sshfs: implement rm via ssh diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index e0163ccf3..257405746 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -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); }