diff --git a/src/storage.js b/src/storage.js index ba7e7e580..72c9b3b35 100644 --- a/src/storage.js +++ b/src/storage.js @@ -43,12 +43,12 @@ function getBackupFilePath(backupConfig, backupId, format) { assert.strictEqual(typeof backupId, 'string'); assert.strictEqual(typeof format, 'string'); - const backupPath = api(backupConfig.provider).getBackupPath(backupConfig); + const basePath = api(backupConfig.provider).getBasePath(backupConfig); if (format === 'tgz') { const fileType = backupConfig.encryption ? '.tar.gz.enc' : '.tar.gz'; - return path.join(backupPath, backupId+fileType); + return path.join(basePath, backupId+fileType); } else { - return path.join(backupPath, backupId); + return path.join(basePath, backupId); } } diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index b58495d9d..e685c9f01 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -1,7 +1,7 @@ 'use strict'; exports = module.exports = { - getBackupPath, + getBasePath, checkPreconditions, upload, @@ -46,7 +46,7 @@ const assert = require('assert'), shell = require('../shell.js'); // storage api -function getBackupPath(apiConfig) { +function getBasePath(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); switch (apiConfig.provider) { @@ -78,7 +78,7 @@ async function checkPreconditions(apiConfig, dataLayout, callback) { debug(`checkPreconditions: ${used} bytes`); - const [error, result] = await safe(df.file(getBackupPath(apiConfig))); + const [error, result] = await safe(df.file(getBasePath(apiConfig))); if (error) return callback(new BoxError(BoxError.FS_ERROR, `Error when checking for disk space: ${error.message}`)); // Check filesystem is mounted so we don't write into the actual folder on disk @@ -318,20 +318,20 @@ function testConfig(apiConfig, callback) { if (!safe.child_process.execSync(`mountpoint -q -- ${apiConfig.mountPoint}`)) return callback(new BoxError(BoxError.BAD_FIELD, `${apiConfig.mountPoint} is not mounted`)); } - const backupPath = getBackupPath(apiConfig); + const basePath = getBasePath(apiConfig); const field = apiConfig.provider === PROVIDER_FILESYSTEM ? 'backupFolder' : 'mountPoint'; - if (!safe.fs.mkdirSync(path.join(backupPath, 'snapshot'), { recursive: true }) && safe.error.code !== 'EEXIST') { - if (safe.error && safe.error.code === 'EACCES') return callback(new BoxError(BoxError.BAD_FIELD, `Access denied. Create the directory and run "chown yellowtent:yellowtent ${backupPath}" on the server`, { field })); + if (!safe.fs.mkdirSync(path.join(basePath, 'snapshot'), { recursive: true }) && safe.error.code !== 'EEXIST') { + if (safe.error && safe.error.code === 'EACCES') return callback(new BoxError(BoxError.BAD_FIELD, `Access denied. Create the directory and run "chown yellowtent:yellowtent ${basePath}" on the server`, { field })); return callback(new BoxError(BoxError.BAD_FIELD, safe.error.message, { field })); } - if (!safe.fs.writeFileSync(path.join(backupPath, 'cloudron-testfile'), 'testcontent')) { - return callback(new BoxError(BoxError.BAD_FIELD, `Unable to create test file as 'yellowtent' user in ${backupPath}: ${safe.error.message}. Check dir/mount permissions`, { field })); + if (!safe.fs.writeFileSync(path.join(basePath, 'cloudron-testfile'), 'testcontent')) { + return callback(new BoxError(BoxError.BAD_FIELD, `Unable to create test file as 'yellowtent' user in ${basePath}: ${safe.error.message}. Check dir/mount permissions`, { field })); } - if (!safe.fs.unlinkSync(path.join(backupPath, 'cloudron-testfile'))) { - return callback(new BoxError(BoxError.BAD_FIELD, `Unable to remove test file as 'yellowtent' user in ${backupPath}: ${safe.error.message}. Check dir/mount permissions`, { field })); + if (!safe.fs.unlinkSync(path.join(basePath, 'cloudron-testfile'))) { + return callback(new BoxError(BoxError.BAD_FIELD, `Unable to remove test file as 'yellowtent' user in ${basePath}: ${safe.error.message}. Check dir/mount permissions`, { field })); } callback(null); diff --git a/src/storage/gcs.js b/src/storage/gcs.js index b5ca80473..6c914282c 100644 --- a/src/storage/gcs.js +++ b/src/storage/gcs.js @@ -1,7 +1,7 @@ 'use strict'; exports = module.exports = { - getBackupPath, + getBasePath, checkPreconditions, upload, @@ -64,7 +64,7 @@ function getBucket(apiConfig) { } // storage api -function getBackupPath(apiConfig) { +function getBasePath(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); return apiConfig.prefix; diff --git a/src/storage/interface.js b/src/storage/interface.js index fb6582d02..55d1fac30 100644 --- a/src/storage/interface.js +++ b/src/storage/interface.js @@ -11,7 +11,7 @@ // for the other API calls we leave it to the backend to retry. this allows // them to tune the concurrency based on failures/rate limits accordingly exports = module.exports = { - getBackupPath, + getBasePath, checkPreconditions, upload, @@ -49,7 +49,7 @@ function injectPrivateFields(newConfig, currentConfig) { // in-place injection of tokens and api keys which came in with constants.SECRET_PLACEHOLDER } -function getBackupPath(apiConfig) { +function getBasePath(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); // Result: path at the backup storage diff --git a/src/storage/noop.js b/src/storage/noop.js index b385ba125..a1a029b93 100644 --- a/src/storage/noop.js +++ b/src/storage/noop.js @@ -1,7 +1,7 @@ 'use strict'; exports = module.exports = { - getBackupPath, + getBasePath, checkPreconditions, upload, @@ -28,7 +28,7 @@ var assert = require('assert'), debug = require('debug')('box:storage/noop'), EventEmitter = require('events'); -function getBackupPath(apiConfig) { +function getBasePath(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); return ''; } diff --git a/src/storage/s3.js b/src/storage/s3.js index 6473a705b..07ad11cc3 100644 --- a/src/storage/s3.js +++ b/src/storage/s3.js @@ -1,7 +1,7 @@ 'use strict'; exports = module.exports = { - getBackupPath, + getBasePath, checkPreconditions, upload, @@ -92,7 +92,7 @@ function getS3Config(apiConfig, callback) { } // storage api -function getBackupPath(apiConfig) { +function getBasePath(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); return apiConfig.prefix;