aboutsummaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-02 00:06:45 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-01-02 00:06:45 -0800
commit3915e01cfbb35a0953255d7bb5e186f8840c852f (patch)
treea1b8512dcb6e3da9930fc0d5160e17ddece37ef6 /src/fs.zig
parent2fc6da125f276cc96ab2131fa7cca63f41cfce6c (diff)
downloadbun-3915e01cfbb35a0953255d7bb5e186f8840c852f.tar.gz
bun-3915e01cfbb35a0953255d7bb5e186f8840c852f.tar.zst
bun-3915e01cfbb35a0953255d7bb5e186f8840c852f.zip
[bun install] Fix `RenameAcrossMountPoints` error
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 19c085f15..2f29ed2f1 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -82,11 +82,16 @@ pub const FileSystem = struct {
dirname_store: *DirnameStore,
filename_store: *FilenameStore,
+ inside_home_dir: bool = false,
_tmpdir: ?std.fs.Dir = null,
threadlocal var tmpdir_handle: ?std.fs.Dir = null;
+ pub fn setInsideHomeDir(this: *FileSystem, home_dir: string) void {
+ this.inside_home_dir = strings.hasPrefix(this.top_level_dir, home_dir);
+ }
+
pub fn tmpdir(fs: *FileSystem) std.fs.Dir {
if (tmpdir_handle == null) {
tmpdir_handle = fs.fs.openTmpDir() catch unreachable;
@@ -97,7 +102,7 @@ pub const FileSystem = struct {
pub fn tmpname(_: *const FileSystem, extname: string, buf: []u8, hash: u64) ![*:0]u8 {
// PRNG was...not so random
- return try std.fmt.bufPrintZ(buf, "{x}{s}", .{ @truncate(u64, @intCast(u128, hash) * @intCast(u128, std.time.nanoTimestamp())), extname });
+ return try std.fmt.bufPrintZ(buf, ".{x}{s}", .{ @truncate(u64, @intCast(u128, hash) * @intCast(u128, std.time.nanoTimestamp())), extname });
}
pub var max_fd: FileDescriptorType = 0;
@@ -514,6 +519,15 @@ pub const FileSystem = struct {
return try std.fs.openDirAbsolute(tmpdir_path, .{ .access_sub_paths = true, .iterate = true });
}
+ pub fn getDefaultTempDir() string {
+ return std.os.getenvZ("BUN_TMPDIR") orelse std.os.getenvZ("TMPDIR") orelse PLATFORM_TMP_DIR;
+ }
+
+ pub fn setTempdir(path: ?string) void {
+ tmpdir_path = path orelse getDefaultTempDir();
+ tmpdir_path_set = true;
+ }
+
pub fn fetchCacheFile(fs: *RealFS, basename: string) !std.fs.File {
const file = try fs._fetchCacheFile(basename);
if (comptime FeatureFlags.store_file_descriptors) {