backups: remove entries from database that don't exist in storage
fixes #772
This commit is contained in:
@@ -5,6 +5,7 @@ exports = module.exports = {
|
||||
checkPreconditions,
|
||||
|
||||
upload,
|
||||
exists,
|
||||
download,
|
||||
copy,
|
||||
|
||||
@@ -100,6 +101,36 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) {
|
||||
sourceStream.pipe(uploadStream);
|
||||
}
|
||||
|
||||
function exists(apiConfig, backupFilePath, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupFilePath, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const bucket = getBucket(apiConfig);
|
||||
|
||||
if (!backupFilePath.endsWith('/')) {
|
||||
const file = bucket.file(backupFilePath);
|
||||
file.getMetadata(function (error) {
|
||||
if (error && error.code === 404) return callback(null, false);
|
||||
if (error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, error.message));
|
||||
|
||||
callback(null, true);
|
||||
});
|
||||
} else {
|
||||
const query = {
|
||||
prefix: backupFilePath,
|
||||
maxResults: 1,
|
||||
autoPaginate: true
|
||||
};
|
||||
|
||||
bucket.getFiles(query, function (error, files) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, files.length !== 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function download(apiConfig, backupFilePath, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupFilePath, 'string');
|
||||
|
||||
Reference in New Issue
Block a user