Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the CACHEDIR.TAG file to the cache directory #14875

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,21 @@ const Listen = union(enum) {
stdio,
};

/// Add the CACHEDIR.TAG file to the cache directory.
/// See http://www.brynosaurus.com/cachedir/.
fn tagCacheDirectory(dir: fs.Dir) !void {
const bytes =
\\Signature: 8a477f597d28d172789f06886806bc55
\\# This file is a cache directory tag created by Zig.
\\# For information about cache directory tags, see:
\\# http://www.brynosaurus.com/cachedir/
;
const file = try dir.createFile("CACHEDIR.TAG", .{});
defer file.close();

try file.writeAll(bytes);
}

fn buildOutputType(
gpa: Allocator,
arena: Allocator,
Expand Down Expand Up @@ -3062,6 +3077,7 @@ fn buildOutputType(
};
};
defer global_cache_directory.handle.close();
try tagCacheDirectory(global_cache_directory.handle);

var cleanup_local_cache_dir: ?fs.Dir = null;
defer if (cleanup_local_cache_dir) |*dir| dir.close();
Expand Down Expand Up @@ -3106,6 +3122,7 @@ fn buildOutputType(
// so we utilize the global one.
break :l global_cache_directory;
};
try tagCacheDirectory(local_cache_directory.handle);

if (build_options.have_llvm and emit_asm != .no) {
// LLVM has no way to set this non-globally.
Expand Down