diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 02b9741b1..d95bc8799 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -116,13 +116,11 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) { }); fileStream.on('finish', function () { - // in test, upload() may or may not be called via sudo script - const BACKUP_UID = parseInt(process.env.SUDO_UID, 10) || process.getuid(); + const backupUid = parseInt(process.env.SUDO_UID, 10) || process.getuid(); // in test, upload() may or may not be called via sudo script - // sshfs and cifs handle ownership through the mount args - if (apiConfig.provider === PROVIDER_FILESYSTEM || apiConfig.provider === PROVIDER_NFS || (apiConfig.provider === PROVIDER_MOUNTPOINT && apiConfig.chown)) { - if (!safe.fs.chownSync(backupFilePath, BACKUP_UID, BACKUP_UID)) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to chown:' + safe.error.message)); - if (!safe.fs.chownSync(path.dirname(backupFilePath), BACKUP_UID, BACKUP_UID)) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to chown:' + safe.error.message)); + if ((apiConfig.provider !== PROVIDER_MOUNTPOINT && apiConfig.provider !== PROVIDER_CIFS) || apiConfig.chown) { + if (!safe.fs.chownSync(backupFilePath, backupUid, backupUid)) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to chown:' + safe.error.message)); + if (!safe.fs.chownSync(path.dirname(backupFilePath), backupUid, backupUid)) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to chown:' + safe.error.message)); } debug('upload %s: done.', backupFilePath); @@ -201,11 +199,8 @@ function copy(apiConfig, oldFilePath, newFilePath) { events.emit('progress', `Copying ${oldFilePath} to ${newFilePath}`); - // sshfs and cifs do not allow preserving attributes - let cpOptions = (apiConfig.provider === PROVIDER_FILESYSTEM || apiConfig.provider === PROVIDER_NFS || (apiConfig.provider === PROVIDER_MOUNTPOINT && apiConfig.preserveAttributes)) ? '-a' : '-dR'; - - // this will hardlink backups saving space - cpOptions += apiConfig.noHardlinks ? '' : 'l'; + let cpOptions = ((apiConfig.provider !== PROVIDER_MOUNTPOINT && apiConfig.provider !== PROVIDER_CIFS) || apiConfig.preserveAttributes) ? '-a' : '-dR'; + cpOptions += apiConfig.noHardlinks ? '' : 'l'; // this will hardlink backups saving space shell.spawn('copy', '/bin/cp', [ cpOptions, oldFilePath, newFilePath ], { }, function (error) { if (error) return events.emit('done', new BoxError(BoxError.EXTERNAL_ERROR, error.message));