sshfs: if remote copy fails, fallback to sshfs based copy

remote copy can file if there is no cp in the remote . for example,
if it was a windows server.
This commit is contained in:
Girish Ramakrishnan
2024-07-22 20:53:19 +02:00
parent 5084ee761e
commit 44678cf5f1

View File

@@ -173,24 +173,16 @@ async function copy(apiConfig, oldFilePath, newFilePath, progressCallback) {
if (apiConfig.provider === PROVIDER_SSHFS) {
const identityFilePath = `/home/yellowtent/platformdata/sshfs/id_rsa_${apiConfig.mountOptions.host}`;
const sshOptions = [];
sshOptions.push('-o');
sshOptions.push('"StrictHostKeyChecking no"');
sshOptions.push('-i');
sshOptions.push(identityFilePath);
sshOptions.push('-p');
sshOptions.push(apiConfig.mountOptions.port);
sshOptions.push(`${apiConfig.mountOptions.user}@${apiConfig.mountOptions.host}`);
oldFilePath = oldFilePath.replace('/mnt/cloudronbackup/', '');
newFilePath = newFilePath.replace('/mnt/cloudronbackup/', '');
const [copyError] = await safe(shell.execArgs('copy', 'ssh', sshOptions.concat([ 'cp', cpOptions, oldFilePath, newFilePath ]), { shell: true }));
if (copyError) throw new BoxError(BoxError.EXTERNAL_ERROR, copyError.message);
} else {
const [copyError] = await safe(shell.execArgs('copy', 'cp', [ cpOptions, oldFilePath, newFilePath ], {}));
if (copyError) throw new BoxError(BoxError.EXTERNAL_ERROR, copyError.message);
const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', apiConfig.mountOptions.port, `${apiConfig.mountOptions.user}@${apiConfig.mountOptions.host}` ];
const sshArgs = sshOptions.concat([ 'cp', cpOptions, oldFilePath.replace('/mnt/cloudronbackup/', ''), newFilePath.replace('/mnt/cloudronbackup/', '') ]);
const [remoteCopyError] = await safe(shell.execArgs('copy', '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
}
const [copyError] = await safe(shell.execArgs('copy', 'cp', [ cpOptions, oldFilePath, newFilePath ], {}));
if (copyError) throw new BoxError(BoxError.EXTERNAL_ERROR, copyError.message);
}
async function remove(apiConfig, filename) {