FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Wait for copy and remove promises to finish by implausible · Pull Request #1730 · nodegit/nodegit · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
44 changes: 25 additions & 19 deletions generate/scripts/utils.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,35 @@ var util = {
},

syncDirs: function(fromDir, toDir) {
let toFilePaths;
let fromFilePaths;
return Promise.all([
util.getFilePathsRelativeToDir(toDir),
util.getFilePathsRelativeToDir(fromDir)
]).then(function(filePaths) {
const toFilePaths = filePaths[0];
const fromFilePaths = filePaths[1];

// Delete files that aren't in fromDir
toFilePaths.forEach(function(filePath) {
if (!util.isFile(path.join(fromDir, filePath))) {
fse.remove(path.join(toDir, filePath));
}
])
.then(function(filePaths) {
toFilePaths = filePaths[0];
fromFilePaths = filePaths[1];

// Delete files that aren't in fromDir
return Promise.all(toFilePaths.map(function(filePath) {
if (!util.isFile(path.join(fromDir, filePath))) {
return fse.remove(path.join(toDir, filePath));
}
return Promise.resolve();
}));
})
.then(function() {
// Copy files that don't exist in toDir or have different contents
return Promise.all(fromFilePaths.map(function(filePath) {
const toFilePath = path.join(toDir, filePath);
const fromFilePath = path.join(fromDir, filePath);
if (!util.isFile(toFilePath) || util.readFile(toFilePath) !== util.readFile(fromFilePath)) {
return fse.copy(fromFilePath, toFilePath);
}
return Promise.resolve();
}));
});

// Copy files that don't exist in toDir or have different contents
fromFilePaths.forEach(function(filePath) {
const toFilePath = path.join(toDir, filePath);
const fromFilePath = path.join(fromDir, filePath);
if (!util.isFile(toFilePath) || util.readFile(toFilePath) !== util.readFile(fromFilePath)) {
fse.copy(fromFilePath, toFilePath);
}
});
});
}
};

Expand Down

Back | FazBrowse Home | New Git URL