From 6cb56cd4d694b5c2d63ce1281d3405f06c127d71 Mon Sep 17 00:00:00 2001 From: Thomas Clement Date: Tue, 9 Dec 2025 20:35:49 +0100 Subject: [PATCH 1/3] Fall back to making a regular copy if hard linking fails (it is pretty typical for Linux distributions to setup home directories on a separate volume). --- pkgm.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index ef0d77a..e5ae51f 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -367,8 +367,14 @@ 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 { + // Create a hard link for files + await Deno.link(sourcePath, targetPath); + } catch { + // Fall back to a regular copy if hard linking fails (it is pretty typical + // for Linux distributions to setup home directories on a separate volume). + await Deno.copyFile(sourcePath, targetPath); + } } else if (fileInfo.isSymlink) { // Recreate symlink in the target directory const linkTarget = await Deno.readLink(sourcePath); From 366b9b41ca3e71ddc8f22a3f6af7572b6caed181 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Wed, 4 Feb 2026 13:03:19 -0500 Subject: [PATCH 2/3] Implement fallback warning for hard linking failure Add fallback warning for hard link failure in mirror_directory function, since this could cause unexpected behavior. --- pkgm.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index e5ae51f..2f0409f 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) { @@ -368,11 +369,12 @@ async function mirror_directory(dst: string, src: string, prefix: string) { await Deno.remove(targetPath); } try { - // Create a hard link for files await Deno.link(sourcePath, targetPath); } catch { - // Fall back to a regular copy if hard linking fails (it is pretty typical - // for Linux distributions to setup home directories on a separate volume). + 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) { From 31cee7697d98a92b1d07c9d57e05f7c6ed709f3a Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Wed, 4 Feb 2026 13:05:59 -0500 Subject: [PATCH 3/3] fix lint --- pkgm.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgm.ts b/pkgm.ts index 2f0409f..f128669 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -372,7 +372,10 @@ async function mirror_directory(dst: string, src: string, prefix: string) { 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"); + console.warn( + "%c! hardlinking failed (possibly cross-device?), falling back to file copy", + "color:yellow", + ); warned_copy_fallback = true; } await Deno.copyFile(sourcePath, targetPath);