use path.join
This commit is contained in:
parent
2216daed43
commit
8bfd116c3b
1 changed files with 10 additions and 14 deletions
24
build.zig
24
build.zig
|
@ -308,7 +308,7 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
.raw => |r| r,
|
||||
.percent_encoded => |p| p,
|
||||
};
|
||||
var it = std.mem.splitBackwardsScalar(u8, path, '/');
|
||||
var it = std.mem.splitBackwardsScalar(u8, path, std.fs.path.sep);
|
||||
return it.first();
|
||||
}
|
||||
|
||||
|
@ -339,11 +339,10 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
hasher.update(download_link);
|
||||
const cache_hash = hasher.final();
|
||||
|
||||
var cache_dir_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const cache_dir = std.fmt.bufPrint(&cache_dir_buf, "{s}/o/{x}/{s}", .{ self.builder.cache_root.path.?, cache_hash, fileNameNoExtension() }) catch @panic("path too long");
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{x}", .{cache_hash}), fileNameNoExtension() });
|
||||
|
||||
return .{
|
||||
.path = try self.builder.allocator.dupe(u8, cache_dir),
|
||||
.path = cache_dir,
|
||||
.hash = cache_hash,
|
||||
};
|
||||
}
|
||||
|
@ -359,14 +358,12 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
hasher.update(link);
|
||||
const cache_hash = hasher.final();
|
||||
|
||||
var cache_dir_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const cache_dir = std.fmt.bufPrint(&cache_dir_buf, "{s}/o/{x}", .{ self.builder.cache_root.path.?, cache_hash }) catch @panic("path too long");
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{x}", .{cache_hash}) });
|
||||
|
||||
const cached_model_dir = std.fmt.allocPrint(
|
||||
const cached_model_dir = try std.fs.path.join(
|
||||
self.builder.allocator,
|
||||
"{s}/{s}",
|
||||
.{ cache_dir, model_dir },
|
||||
) catch @panic("OOM");
|
||||
&[_][]const u8{ cache_dir, model_dir },
|
||||
);
|
||||
defer self.builder.allocator.free(cached_model_dir);
|
||||
|
||||
// Check if already cached
|
||||
|
@ -378,11 +375,10 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
// Not cached, need to download
|
||||
std.fs.cwd().makePath(cache_dir) catch @panic("Could not create cache directory");
|
||||
|
||||
const archive = std.fmt.allocPrint(
|
||||
const archive = try std.fs.path.join(
|
||||
self.builder.allocator,
|
||||
"{s}/{s}",
|
||||
.{ cache_dir, fileName(download_uri) },
|
||||
) catch @panic("OOM");
|
||||
&[_][]const u8{ cache_dir, fileName(download_uri) },
|
||||
);
|
||||
defer self.builder.allocator.free(archive);
|
||||
|
||||
// Download
|
||||
|
|
Loading…
Add table
Reference in a new issue