Skip to content
This repository was archived by the owner on Feb 12, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ Client.prototype.downloadFile = function(params) {
var downloader = new EventEmitter();
var localFile = params.localFile;
var s3Params = extend({}, params.s3Params);

var dirPath = path.dirname(localFile);
var dirPath = (localFile.match(/\/$/))?localFile:path.dirname(localFile);
downloader.progressAmount = 0;
mkdirp(dirPath, function(err) {
if (err) {
Expand Down Expand Up @@ -1018,19 +1017,29 @@ function syncDir(self, params, directionIsToS3) {
return;
}


// special case for directories when deleteRemoved is true and we're
// downloading a dir from S3. We don't add directories to the list
// unless this case is true, so we assert that fact here.
if (localFileStat && localFileStat.isDirectory()) {
assert.ok(!directionIsToS3);
assert.ok(deleteRemoved);

localFileCursor += 1;
setImmediate(checkDoMoreWork);

if (!s3Object || s3Object.key.indexOf(localFileStat.s3Path) !== 0) {
if (!s3Object) {
deleteLocalDir(); // no more s3 objects
}
else if (localFileStat.s3Path > s3Object.key){
downloadS3Object(); // previous item, download it.
}
else if (s3Object.key.indexOf(localFileStat.s3Path) !== 0 ){ // starts with this folder name
deleteLocalDir();
} else if (localFileStat.s3Path === s3Object.key) { // same folder (don't need to download it.)
skipThisOne();
} else if (s3Object.key.indexOf(localFileStat.s3Path) === 0){
localFileCursor += 1;
setImmediate(checkDoMoreWork); // skip this, just a local folder
}

return;
}

Expand Down Expand Up @@ -1069,8 +1078,11 @@ function syncDir(self, params, directionIsToS3) {
}

function deleteLocalDir() {
var fullPath = path.join(localDir, localFileStat.path);
localFileCursor += 1;
setImmediate(checkDoMoreWork);
if (!deleteRemoved) return;
ee.deleteTotal += 1;
var fullPath = path.join(localDir, localFileStat.path);
rimraf(fullPath, function(err) {
if (fatalError) return;
if (err && err.code !== 'ENOENT') return handleError(err);
Expand Down Expand Up @@ -1237,7 +1249,9 @@ function syncDir(self, params, directionIsToS3) {
ee.emit('progress');
data.Contents.forEach(function(object) {
object.key = object.Key.substring(prefix.length);
allS3Objects.push(object);
if (object.key != ""){
allS3Objects.push(object);
}
});
checkDoMoreWork();
});
Expand Down