Skip to content

Commit

Permalink
fixed missing file checks
Browse files Browse the repository at this point in the history
  • Loading branch information
run2go committed Mar 1, 2024
1 parent 969f571 commit cbecb9d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions extension/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ async function copyFiles(path, directory) {
try {
let handledFiles = 0;
for (const [src, dest] of filePairs) {
if (!fs.existsSync(src)) { // Skip this pair if source does not exist
console.warn(`File "${src}" is missing.`);
continue;
}
const srcStat = await fs.stat(src);
const destStat = await fs.stat(dest);

let destStat = { mtime:0 }; // Set default destStats
if (!fs.existsSync(dest)) { // Ensure the destination directory if the dest file is missing
await fs.ensureDir(path.dirname(dest));
} else {
destStat = await fs.stat(dest);
}

// Check if source file is newer than destination file
if (srcStat.mtime > destStat.mtime) {
await fs.ensureDir(path.dirname(dest));
await fs.copyFile(src, dest);
console.debug(`Copied "${src}" to "${dest}"`);
handledFiles++;
Expand All @@ -47,4 +56,4 @@ async function copyFiles(path, directory) {

module.exports = {
copyFiles,
};
};

0 comments on commit cbecb9d

Please sign in to comment.