backups: remove entries from database that don't exist in storage

fixes #772
This commit is contained in:
Girish Ramakrishnan
2021-02-18 16:51:43 -08:00
parent a5c4b5d8a1
commit c4dffa393b
7 changed files with 212 additions and 43 deletions

View File

@@ -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');