Initial version of flat-file uploader

This commit is contained in:
Girish Ramakrishnan
2017-09-22 14:40:37 -07:00
parent 2f6cb3e913
commit 0a60365143
6 changed files with 216 additions and 39 deletions

View File

@@ -34,11 +34,11 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) {
assert.strictEqual(typeof sourceStream, 'object');
assert.strictEqual(typeof callback, 'function');
debug('upload: %s', backupFilePath);
mkdirp(path.dirname(backupFilePath), function (error) {
if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
safe.fs.unlinkSync(backupFilePath); // remove any hardlink
var fileStream = fs.createWriteStream(backupFilePath);
fileStream.on('error', function (error) {
@@ -47,11 +47,9 @@ function upload(apiConfig, backupFilePath, sourceStream, callback) {
});
fileStream.on('close', function () {
debug('[%s] upload: changing ownership.', backupFilePath);
if (!safe.child_process.execSync('chown -R ' + BACKUP_USER + ':' + BACKUP_USER + ' ' + path.dirname(backupFilePath))) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, safe.error.message));
debug('[%s] upload: done.', backupFilePath);
debug('upload %s: done.', backupFilePath);
callback(null);
});