diff --git a/pkgm.ts b/pkgm.ts index ef0d77a..f128669 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -347,6 +347,7 @@ async function query_pkgx( } async function mirror_directory(dst: string, src: string, prefix: string) { + let warned_copy_fallback = false; await processEntry(join(src, prefix), join(dst, prefix)); async function processEntry(sourcePath: string, targetPath: string) { @@ -367,8 +368,18 @@ async function mirror_directory(dst: string, src: string, prefix: string) { if (existsSync(targetPath)) { await Deno.remove(targetPath); } - // Create a hard link for files - await Deno.link(sourcePath, targetPath); + try { + await Deno.link(sourcePath, targetPath); + } catch { + if (!warned_copy_fallback) { + console.warn( + "%c! hardlinking failed (possibly cross-device?), falling back to file copy", + "color:yellow", + ); + warned_copy_fallback = true; + } + await Deno.copyFile(sourcePath, targetPath); + } } else if (fileInfo.isSymlink) { // Recreate symlink in the target directory const linkTarget = await Deno.readLink(sourcePath);