| ... | @@ -153,6 +153,9 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! | ... | @@ -153,6 +153,9 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 153 | defer pvd.close(); | 153 | defer pvd.close(); |
| 154 | try pvd.deleteTree(".git"); | 154 | try pvd.deleteTree(".git"); |
| 155 | } | 155 | } |
| | 156 | var pvd = try std.fs.cwd().openIterableDir(pv, .{}); |
| | 157 | defer pvd.close(); |
| | 158 | try setTreeReadOnly(pvd, options.alloc); |
| 156 | return pv; | 159 | return pv; |
| 157 | } | 160 | } |
| 158 | if (!try u.does_folder_exist(p)) { | 161 | if (!try u.does_folder_exist(p)) { |
| ... | @@ -187,6 +190,9 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! | ... | @@ -187,6 +190,9 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 187 | try d.type.pull(options.alloc, d.path, pv); | 190 | try d.type.pull(options.alloc, d.path, pv); |
| 188 | if (try u.validate_hash(options.alloc, d.version, file_path)) { | 191 | if (try u.validate_hash(options.alloc, d.version, file_path)) { |
| 189 | try std.fs.cwd().deleteFile(file_path); | 192 | try std.fs.cwd().deleteFile(file_path); |
| | 193 | var pvd = try std.fs.cwd().openIterableDir(pv, .{}); |
| | 194 | defer pvd.close(); |
| | 195 | try setTreeReadOnly(pvd, options.alloc); |
| 190 | return pv; | 196 | return pv; |
| 191 | } | 197 | } |
| 192 | try std.fs.cwd().deleteTree(pv); | 198 | try std.fs.cwd().deleteTree(pv); |
| ... | @@ -370,3 +376,18 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str | ... | @@ -370,3 +376,18 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str |
| 370 | } | 376 | } |
| 371 | return list.toOwnedSlice(); | 377 | return list.toOwnedSlice(); |
| 372 | } | 378 | } |
| | 379 | |
| | 380 | fn setTreeReadOnly(idir: std.fs.IterableDir, alloc: std.mem.Allocator) !void { |
| | 381 | var walker = try idir.walk(alloc); |
| | 382 | defer walker.deinit(); |
| | 383 | |
| | 384 | while (try walker.next()) |entry| { |
| | 385 | if (entry.kind != .file) continue; |
| | 386 | var file = try idir.dir.openFile(entry.path, .{}); |
| | 387 | defer file.close(); |
| | 388 | var metadata = try file.metadata(); |
| | 389 | var perms = metadata.permissions(); |
| | 390 | perms.setReadOnly(true); |
| | 391 | try file.setPermissions(perms); |
| | 392 | } |
| | 393 | } |