Skip to content

Commit 2b5e188

Browse files
authored
Merge pull request #75 from tclementdev/main
Fall back to making a regular copy if hard linking fails
2 parents e3934de + 31cee76 commit 2b5e188

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkgm.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ async function query_pkgx(
347347
}
348348

349349
async function mirror_directory(dst: string, src: string, prefix: string) {
350+
let warned_copy_fallback = false;
350351
await processEntry(join(src, prefix), join(dst, prefix));
351352

352353
async function processEntry(sourcePath: string, targetPath: string) {
@@ -367,8 +368,18 @@ async function mirror_directory(dst: string, src: string, prefix: string) {
367368
if (existsSync(targetPath)) {
368369
await Deno.remove(targetPath);
369370
}
370-
// Create a hard link for files
371-
await Deno.link(sourcePath, targetPath);
371+
try {
372+
await Deno.link(sourcePath, targetPath);
373+
} catch {
374+
if (!warned_copy_fallback) {
375+
console.warn(
376+
"%c! hardlinking failed (possibly cross-device?), falling back to file copy",
377+
"color:yellow",
378+
);
379+
warned_copy_fallback = true;
380+
}
381+
await Deno.copyFile(sourcePath, targetPath);
382+
}
372383
} else if (fileInfo.isSymlink) {
373384
// Recreate symlink in the target directory
374385
const linkTarget = await Deno.readLink(sourcePath);

0 commit comments

Comments
 (0)