Skip to content

Commit

Permalink
Fix empty directory crashes (local and remote) for sync
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswilburn committed May 31, 2022
1 parent 1beab0f commit a7bdb68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions lib/expandMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,33 @@ var filterFile = function(file, patterns, strict) {
// returns all files that match
var expand = async function(from, dir, patterns) {
var fullDir = path.join(from, dir);
var files = await fs.readdir(fullDir);
try {
var files = await fs.readdir(fullDir);
} catch (err) {
console.log(`Unable to read directory ${fullDir} - does it exist?`);
return [];
}
var matching = [];
var affirmative = patterns.filter(p => p[0] != "!");
var negative = patterns.filter(p => p[0] == "!");
for (var i = 0; i < files.length; i++) {
var f = files[i];
var full = path.join(from, dir, f);
var relative = path.relative(from, full);
var stat = await fs.stat(full);
if (stat.isDirectory()) {
var children = await expand(from, relative, patterns);
matching.push(...children);
} else {
var matched = filterFile(relative, affirmative);
var notExcluded = filterFile(relative, negative, true);
if (matched && notExcluded) {
matching.push(full);
try {
var stat = await fs.stat(full);
if (stat.isDirectory()) {
var children = await expand(from, relative, patterns);
matching.push(...children);
} else {
var matched = filterFile(relative, affirmative);
var notExcluded = filterFile(relative, negative, true);
if (matched && notExcluded) {
matching.push(full);
}
}
} catch (err) {
console.log(`Unable to expand matches for path ${f}`);
}
}
return matching;
Expand Down
2 changes: 1 addition & 1 deletion lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var download = async function (Bucket, Key) {
// get a single page of results from S3
var getRemote = async function (Bucket, Prefix, Marker = null) {
var results = await s3.send(new ListObjectsV2Command({ Bucket, Prefix, Marker }));
var items = results.Contents.map(function (obj) {
var items = (results.Contents || []).map(function (obj) {
return {
file: obj.Key.replace(/.*\/synced\//, ""),
size: obj.Size,
Expand Down

0 comments on commit a7bdb68

Please sign in to comment.