diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 172d0c428..2f8d213a5 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -210,7 +210,9 @@ async function copyInternal(config, fromPath, toPath, options, progressCallback) if (config._provider === mounts.MOUNT_TYPE_SSHFS) { // we use a temporary key file instead of passing it as stdin - const identityFilePath = `/tmp/identity_file_${config._managedMountPath.replaceAll('/', '-')}`; + const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`; + // have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it + safe.fs.unlinkSync(identityFilePath); if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`); const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ]; @@ -271,7 +273,9 @@ async function removeDir(config, limits, remotePathPrefix, progressCallback) { if (config._provider === mounts.MOUNT_TYPE_SSHFS) { // we use a temporary key file instead of passing it as stdin - const identityFilePath = `/tmp/identity_file_${config._managedMountPath.replaceAll('/', '-')}`; + const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`; + // have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it + safe.fs.unlinkSync(identityFilePath); if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`); const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ];