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,
|
.raw => |r| r,
|
||||||
.percent_encoded => |p| p,
|
.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();
|
return it.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,11 +339,10 @@ fn DownloadStep(comptime link: []const u8) type {
|
||||||
hasher.update(download_link);
|
hasher.update(download_link);
|
||||||
const cache_hash = hasher.final();
|
const cache_hash = hasher.final();
|
||||||
|
|
||||||
var cache_dir_buf: [std.fs.max_path_bytes]u8 = undefined;
|
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() });
|
||||||
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");
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.path = try self.builder.allocator.dupe(u8, cache_dir),
|
.path = cache_dir,
|
||||||
.hash = cache_hash,
|
.hash = cache_hash,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -359,14 +358,12 @@ fn DownloadStep(comptime link: []const u8) type {
|
||||||
hasher.update(link);
|
hasher.update(link);
|
||||||
const cache_hash = hasher.final();
|
const cache_hash = hasher.final();
|
||||||
|
|
||||||
var cache_dir_buf: [std.fs.max_path_bytes]u8 = undefined;
|
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 cache_dir = std.fmt.bufPrint(&cache_dir_buf, "{s}/o/{x}", .{ self.builder.cache_root.path.?, cache_hash }) catch @panic("path too long");
|
|
||||||
|
|
||||||
const cached_model_dir = std.fmt.allocPrint(
|
const cached_model_dir = try std.fs.path.join(
|
||||||
self.builder.allocator,
|
self.builder.allocator,
|
||||||
"{s}/{s}",
|
&[_][]const u8{ cache_dir, model_dir },
|
||||||
.{ cache_dir, model_dir },
|
);
|
||||||
) catch @panic("OOM");
|
|
||||||
defer self.builder.allocator.free(cached_model_dir);
|
defer self.builder.allocator.free(cached_model_dir);
|
||||||
|
|
||||||
// Check if already cached
|
// Check if already cached
|
||||||
|
@ -378,11 +375,10 @@ fn DownloadStep(comptime link: []const u8) type {
|
||||||
// Not cached, need to download
|
// Not cached, need to download
|
||||||
std.fs.cwd().makePath(cache_dir) catch @panic("Could not create cache directory");
|
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,
|
self.builder.allocator,
|
||||||
"{s}/{s}",
|
&[_][]const u8{ cache_dir, fileName(download_uri) },
|
||||||
.{ cache_dir, fileName(download_uri) },
|
);
|
||||||
) catch @panic("OOM");
|
|
||||||
defer self.builder.allocator.free(archive);
|
defer self.builder.allocator.free(archive);
|
||||||
|
|
||||||
// Download
|
// Download
|
||||||
|
|
Loading…
Add table
Reference in a new issue