aboutsummaryrefslogtreecommitdiff
path: root/src/Package/Fetch/git.zig
diff options
context:
space:
mode:
authorIgor Anić <igor.anic@gmail.com>2024-03-30 22:43:27 +0100
committerIgor Anić <igor.anic@gmail.com>2024-04-09 15:00:21 +0200
commit5a38924a7d41fee0ac5544d9ddb85ce82bc92030 (patch)
tree63ad1a3f562e0ab1c2dd802aa466b853a79cf89e /src/Package/Fetch/git.zig
parentad60b6c1edfc9ee30cf137fb1d56269e0af0941c (diff)
downloadzig-5a38924a7d41fee0ac5544d9ddb85ce82bc92030.tar.gz
zig-5a38924a7d41fee0ac5544d9ddb85ce82bc92030.zip
fetch.git: collect file create diagnostic errors
On case insensitive file systems, don't overwrite files with same name in different casing. Add diagnostic error so caller could decide what to do.
Diffstat (limited to 'src/Package/Fetch/git.zig')
-rw-r--r--src/Package/Fetch/git.zig19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Package/Fetch/git.zig b/src/Package/Fetch/git.zig
index 36652bd88c..d7cdd8483c 100644
--- a/src/Package/Fetch/git.zig
+++ b/src/Package/Fetch/git.zig
@@ -46,6 +46,10 @@ pub const Diagnostics = struct {
file_name: []const u8,
link_name: []const u8,
},
+ unable_to_create_file: struct {
+ code: anyerror,
+ file_name: []const u8,
+ },
};
pub fn deinit(d: *Diagnostics) void {
@@ -55,6 +59,9 @@ pub const Diagnostics = struct {
d.allocator.free(info.file_name);
d.allocator.free(info.link_name);
},
+ .unable_to_create_file => |info| {
+ d.allocator.free(info.file_name);
+ },
}
}
d.errors.deinit(d.allocator);
@@ -119,11 +126,19 @@ pub const Repository = struct {
try repository.checkoutTree(subdir, entry.oid, sub_path, diagnostics);
},
.file => {
- var file = try dir.createFile(entry.name, .{});
- defer file.close();
try repository.odb.seekOid(entry.oid);
const file_object = try repository.odb.readObject();
if (file_object.type != .blob) return error.InvalidFile;
+ var file = dir.createFile(entry.name, .{ .exclusive = true }) catch |e| {
+ const file_name = try std.fs.path.join(diagnostics.allocator, &.{ current_path, entry.name });
+ errdefer diagnostics.allocator.free(file_name);
+ try diagnostics.errors.append(diagnostics.allocator, .{ .unable_to_create_file = .{
+ .code = e,
+ .file_name = file_name,
+ } });
+ continue;
+ };
+ defer file.close();
try file.writeAll(file_object.data);
try file.sync();
},