From fde48b5c2d30aa874a9f74b6f1a8745637a78625 Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Thu, 31 Aug 2023 16:14:28 -0700 Subject: [PATCH] Use `$XDG_CACHE_HOME/bun` instead of `$XDG_CACHE_HOME/.bun` (when the var is set). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses the comment at https://github.com/oven-sh/bun/issues/1678#issuecomment-1668660285 > … I have yet to see see any other program use a `.` prefix for folders > *inside* the XDG convention folders. This may cause the folder to be > unexpectedly hidden when viewing it in a file explorer app or running > `ls` without `-a`. (That is, someone may expect `~/.cache` to be > hidden — but that all folders are visible once they are viewing that > hidden folder.) The only previous workaround would have been to set `$BUN_INSTALL`, but that affects more than the cache directory. (And people who have been using `$XDG_CACHE_HOME` presumably want to opt into the convention that all cache directories are grouped into a single place that is easy to audit and clean, separate from all config data.) Since this: - only affects the subset of users who have explictly opted into `$XDG_CACHE_HOME`, and - only affects cache data, which is meant to be safe to abandon/lose at any moment, … it shouldn't be harmful to leave the old directory lying around and allow a new one to be created. But it would also be possible to move the existing directory with an additional change. --- src/install/install.zig | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/install/install.zig b/src/install/install.zig index 768113d3524c5..3288de99038eb 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -3674,7 +3674,7 @@ pub const PackageManager = struct { } if (env.map.get("XDG_CACHE_HOME")) |dir| { - var parts = [_]string{ dir, ".bun/", "install/", "cache/" }; + var parts = [_]string{ dir, "bun/", "install/", "cache/" }; return CacheDir{ .path = Fs.FileSystem.instance.abs(&parts), .is_node_modules = false }; } @@ -4429,7 +4429,7 @@ pub const PackageManager = struct { if (bun.getenvZ("XDG_CACHE_HOME") orelse bun.getenvZ("HOME")) |home_dir| { var buf: [bun.MAX_PATH_BYTES]u8 = undefined; - var parts = [_]string{ ".bun", "install", "global" }; + var parts = [_]string{ "bun", "install", "global" }; var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPathIterable(path, .{}); } @@ -4459,7 +4459,17 @@ pub const PackageManager = struct { return try std.fs.cwd().makeOpenPathIterable(path, .{}); } - if (bun.getenvZ("XDG_CACHE_HOME") orelse bun.getenvZ("HOME")) |home_dir| { + if (bun.getenvZ("XDG_CACHE_HOME")) |home_dir| { + var buf: [bun.MAX_PATH_BYTES]u8 = undefined; + var parts = [_]string{ + "bun", + "bin", + }; + var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); + return try std.fs.cwd().makeOpenPathIterable(path, .{}); + } + + if (orelse bun.getenvZ("HOME")) |home_dir| { var buf: [bun.MAX_PATH_BYTES]u8 = undefined; var parts = [_]string{ ".bun",