diff --git a/src/backups.js b/src/backups.js index a4bceee18..17c73e0d0 100644 --- a/src/backups.js +++ b/src/backups.js @@ -215,16 +215,19 @@ function get(backupId, callback) { }); } +// This is not part of the storage api, since we don't want to pull the "format" logistics into that function getBackupFilePath(backupConfig, backupId, format) { assert.strictEqual(typeof backupConfig, 'object'); assert.strictEqual(typeof backupId, 'string'); assert.strictEqual(typeof format, 'string'); + const backupPath = api(backupConfig.provider).getBackupPath(backupConfig); + if (format === 'tgz') { const fileType = backupConfig.encryption ? '.tar.gz.enc' : '.tar.gz'; - return path.join(backupConfig.prefix || backupConfig.backupFolder || '', backupId+fileType); + return path.join(backupPath, backupId+fileType); } else { - return path.join(backupConfig.prefix || backupConfig.backupFolder || '', backupId); + return path.join(backupPath, backupId); } } diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index bf2f08e33..4ab00ff2d 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -1,6 +1,8 @@ 'use strict'; exports = module.exports = { + getBackupPath: getBackupPath, + upload: upload, download: download, @@ -28,6 +30,12 @@ var assert = require('assert'), shell = require('../shell.js'); // storage api +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + + return apiConfig.backupFolder; +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string'); diff --git a/src/storage/gcs.js b/src/storage/gcs.js index cc52e070d..278007f03 100644 --- a/src/storage/gcs.js +++ b/src/storage/gcs.js @@ -1,6 +1,8 @@ 'use strict'; exports = module.exports = { + getBackupPath: getBackupPath, + upload: upload, download: download, copy: copy, @@ -57,6 +59,12 @@ function getBucket(apiConfig) { } // storage api +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + + return apiConfig.prefix; +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string'); diff --git a/src/storage/interface.js b/src/storage/interface.js index da2120e9e..78f27b80d 100644 --- a/src/storage/interface.js +++ b/src/storage/interface.js @@ -11,6 +11,8 @@ // 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: getBackupPath, + upload: upload, download: download, @@ -41,6 +43,13 @@ function injectPrivateFields(newConfig, currentConfig) { // in-place injection of tokens and api keys which came in with constants.SECRET_PLACEHOLDER } +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + + // Result: path at the backup storage + return '/'; +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string'); diff --git a/src/storage/noop.js b/src/storage/noop.js index 988c06f44..aa57f7935 100644 --- a/src/storage/noop.js +++ b/src/storage/noop.js @@ -1,6 +1,8 @@ 'use strict'; exports = module.exports = { + getBackupPath: getBackupPath, + upload: upload, download: download, downloadDir: downloadDir, @@ -21,6 +23,11 @@ var assert = require('assert'), debug = require('debug')('box:storage/noop'), EventEmitter = require('events'); +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + return ''; +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string'); diff --git a/src/storage/s3.js b/src/storage/s3.js index c497d335e..8a9848127 100644 --- a/src/storage/s3.js +++ b/src/storage/s3.js @@ -1,6 +1,8 @@ 'use strict'; exports = module.exports = { + getBackupPath: getBackupPath, + upload: upload, download: download, copy: copy, @@ -83,6 +85,12 @@ function getS3Config(apiConfig, callback) { } // storage api +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + + return apiConfig.prefix; +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string'); diff --git a/src/storage/sshfs.js b/src/storage/sshfs.js index c69065c37..d712672bb 100644 --- a/src/storage/sshfs.js +++ b/src/storage/sshfs.js @@ -1,6 +1,8 @@ 'use strict'; exports = module.exports = { + getBackupPath: getBackupPath, + upload: upload, download: download, @@ -42,6 +44,12 @@ function translateConfig(apiConfig) { } // storage api +function getBackupPath(apiConfig) { + assert.strictEqual(typeof apiConfig, 'object'); + + return path.join(apiConfig.mountPoint, apiConfig.prefix); +} + function upload(apiConfig, backupFilePath, sourceStream, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof backupFilePath, 'string');