s3: fix restore
This commit is contained in:
@@ -70,13 +70,10 @@ function download(apiConfig, sourceFilePath, callback) {
|
||||
|
||||
debug('download: %s', sourceFilePath);
|
||||
|
||||
var ps = new PassThrough();
|
||||
if (!safe.fs.existsSync(sourceFilePath)) return callback(new BackupsError(BackupsError.NOT_FOUND, 'File not found'));
|
||||
|
||||
var fileStream = fs.createReadStream(sourceFilePath);
|
||||
fileStream.on('error', function (error) {
|
||||
ps.emit('error', new BackupsError(BackupsError.NOT_FOUND, error.message));
|
||||
});
|
||||
fileStream.pipe(ps);
|
||||
callback(null, ps);
|
||||
callback(null, fileStream);
|
||||
}
|
||||
|
||||
function downloadDir(apiConfig, backupFilePath, destDir, callback) {
|
||||
|
||||
+14
-4
@@ -206,11 +206,21 @@ function downloadDir(apiConfig, backupFilePath, destDir, callback) {
|
||||
mkdirp(path.dirname(path.join(destDir, relativePath)), function (error) {
|
||||
if (error) return iteratorCallback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
|
||||
var destStream = fs.createWriteStream(path.join(destDir, relativePath));
|
||||
destStream.on('error', function (error) {
|
||||
return iteratorCallback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
download(apiConfig, content.Key, function (error, sourceStream) {
|
||||
if (error) return iteratorCallback(error);
|
||||
|
||||
var destStream = fs.createWriteStream(path.join(destDir, relativePath));
|
||||
|
||||
destStream.on('open', function () {
|
||||
sourceStream.pipe(destStream);
|
||||
});
|
||||
|
||||
destStream.on('error', function (error) {
|
||||
return iteratorCallback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
});
|
||||
|
||||
destStream.on('finish', iteratorCallback);
|
||||
});
|
||||
download(apiConfig, content.Key, destStream, iteratorCallback);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user