diff --git a/src/mounts.js b/src/mounts.js index 88b95703d..9f29b0ef8 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -140,7 +140,7 @@ async function renderMountFile(mount) { options = 'discard,defaults,noatime'; break; case exports.MOUNT_TYPE_SSHFS: { - const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${mountOptions.host}`); + const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `identity_file_${path.basename(hostPath)}`); if (!safe.fs.writeFileSync(keyFilePath, `${mount.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write private key: ${safe.error.message}`); type = 'fuse.sshfs'; @@ -160,14 +160,14 @@ async function renderMountFile(mount) { async function removeMount(mount) { assert.strictEqual(typeof mount, 'object'); - const { hostPath, mountType, mountOptions } = mount; + const { hostPath, mountType } = mount; if (constants.TEST) return; await safe(shell.sudo([ RM_MOUNT_CMD, hostPath ], {}), { debug }); // ignore any error if (mountType === exports.MOUNT_TYPE_SSHFS) { - const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${mountOptions.host}`); + const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `identity_file_${path.basename(hostPath)}`); safe.fs.unlinkSync(keyFilePath); } else if (mountType === exports.MOUNT_TYPE_CIFS) { const out = await shell.spawn('systemd-escape', [ '-p', hostPath ], { encoding: 'utf8' }); diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 14cc349b1..578613492 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -208,7 +208,7 @@ async function copyInternal(config, fromPath, toPath, options, progressCallback) cpOptions += config.noHardlinks ? '' : 'l'; // this will hardlink backups saving space if (config._provider === mounts.MOUNT_TYPE_SSHFS) { - const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${config.mountOptions.host}`); + const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `identity_file_${path.basename(config._managedMountPath)}`); const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ]; const sshArgs = sshOptions.concat([ 'cp', cpOptions, path.join(config.prefix, fromPath), path.join(config.prefix, toPath) ]); @@ -264,7 +264,7 @@ async function removeDir(config, remotePathPrefix, progressCallback) { progressCallback({ message: `Removing directory ${fullPathPrefix}` }); if (config._provider === mounts.MOUNT_TYPE_SSHFS) { - const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${config.mountOptions.host}`); + const identityFilePath = path.join(paths.SSHFS_KEYS_DIR, `identity_file_${path.basename(config._managedMountPath)}`); const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ]; const sshArgs = sshOptions.concat([ 'rm', '-rf', path.join(config.prefix, remotePathPrefix) ]);