Skip to content

Commit

Permalink
simplify logic to: if stat fails, check if symlink and notify if so
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Jan 31, 2024
1 parent c1a68fe commit 7968c49
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/cli/src/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,34 @@ const copyDir = async (src, dst, options) => {

const promises = files.map(async (file) => {
const srcItem = path.resolve(src, file);
const srcStat = fse.lstatSync(srcItem);
const srcIsFile = srcStat.isFile();
const srcIsSymbolicLink = srcStat.isSymbolicLink();

const dstItem = path.resolve(dst, file);
const dstExists = fileExistsSync(dstItem);
if (!options.filter(srcItem)) {
return null;
}

if (srcIsFile || srcIsSymbolicLink) {
if (srcIsSymbolicLink && !fileExistsSync(srcItem)) {
let srcStat;
try {
srcStat = fse.statSync(srcItem);
} catch (err) {
// If the file is a symlink and the target doesn't exist, skip it.
if (fse.lstatSync(srcItem).isSymbolicLink()) {
console.warn(
colors.yellow(
`\n! Warning: symlink "${srcItem}" points to a non-existent file. Skipping!\n`
)
);
options.onSkip(dstItem);
return null;
}

// otherwise, rethrow the error
throw err;
}

const srcIsFile = srcStat.isFile();

const dstItem = path.resolve(dst, file);
const dstExists = fileExistsSync(dstItem);
if (!options.filter(srcItem)) {
return null;
}

if (srcIsFile) {
if (dstExists) {
if (!options.clobber) {
options.onSkip(dstItem);
Expand Down

0 comments on commit 7968c49

Please sign in to comment.