Skip to content

Commit

Permalink
Use $XDG_CACHE_HOME/bun instead of $XDG_CACHE_HOME/.bun (when the…
Browse files Browse the repository at this point in the history
… var is set).

This addresses the comment at oven-sh#1678 (comment)

> … 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.
  • Loading branch information
lgarron committed Aug 31, 2023
1 parent bd7262f commit fde48b5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/install/install.zig
Expand Up @@ -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 };
}

Expand Down Expand Up @@ -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, .{});
}
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit fde48b5

Please sign in to comment.