aboutsummaryrefslogtreecommitdiff
path: root/src/install/install.zig
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-02-24 15:53:26 +0200
committerGravatar GitHub <noreply@github.com> 2023-02-24 05:53:26 -0800
commite887a064fb63347b4a4b21c282c1db01dfee98b1 (patch)
tree6270a7ce5527ea06d709d4b92e14623518e0f5b5 /src/install/install.zig
parent6e4908e51793d82d3b6924b2ede9a02f1e95bf37 (diff)
downloadbun-e887a064fb63347b4a4b21c282c1db01dfee98b1.tar.gz
bun-e887a064fb63347b4a4b21c282c1db01dfee98b1.tar.zst
bun-e887a064fb63347b4a4b21c282c1db01dfee98b1.zip
prefer `bun.copy()` over `std.mem.copy()` (#2152)
Diffstat (limited to 'src/install/install.zig')
-rw-r--r--src/install/install.zig45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/install/install.zig b/src/install/install.zig
index 07bd06692..0c280ccaa 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -81,7 +81,6 @@ const String = Semver.String;
const GlobalStringBuilder = @import("../string_builder.zig");
const SlicedString = Semver.SlicedString;
const Repository = @import("./repository.zig").Repository;
-const StructBuilder = @import("../builder.zig");
const Bin = @import("./bin.zig").Bin;
const Dependency = @import("./dependency.zig");
const Behavior = @import("./dependency.zig").Behavior;
@@ -799,7 +798,7 @@ const PackageInstall = struct {
var total: usize = 0;
var read: usize = 0;
- std.mem.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ ".bun-tag");
+ bun.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ ".bun-tag");
this.destination_dir_subpath_buf[this.destination_dir_subpath.len + std.fs.path.sep_str.len + ".bun-tag".len] = 0;
const bun_tag_path: [:0]u8 = this.destination_dir_subpath_buf[0 .. this.destination_dir_subpath.len + std.fs.path.sep_str.len + ".bun-tag".len :0];
defer this.destination_dir_subpath_buf[this.destination_dir_subpath.len] = 0;
@@ -861,7 +860,7 @@ const PackageInstall = struct {
var total: usize = 0;
var read: usize = 0;
- std.mem.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ "package.json");
+ bun.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ "package.json");
this.destination_dir_subpath_buf[this.destination_dir_subpath.len + std.fs.path.sep_str.len + "package.json".len] = 0;
var package_json_path: [:0]u8 = this.destination_dir_subpath_buf[0 .. this.destination_dir_subpath.len + std.fs.path.sep_str.len + "package.json".len :0];
defer this.destination_dir_subpath_buf[this.destination_dir_subpath.len] = 0;
@@ -987,7 +986,7 @@ const PackageInstall = struct {
std.os.mkdirat(destination_dir_.dir.fd, entry.path, 0o755) catch {};
},
.File => {
- std.mem.copy(u8, &stackpath, entry.path);
+ bun.copy(u8, &stackpath, entry.path);
stackpath[entry.path.len] = 0;
var path: [:0]u8 = stackpath[0..entry.path.len :0];
var basename: [:0]u8 = stackpath[entry.path.len - entry.basename.len .. entry.path.len :0];
@@ -1681,7 +1680,7 @@ pub const PackageManager = struct {
const index = @truncate(DependencyID, this.lockfile.buffers.dependencies.items.len);
this.lockfile.buffers.dependencies.append(this.allocator, cloned_dependency) catch unreachable;
this.lockfile.buffers.resolutions.append(this.allocator, invalid_package_id) catch unreachable;
- if (Environment.allow_assert) std.debug.assert(this.lockfile.buffers.dependencies.items.len == this.lockfile.buffers.resolutions.items.len);
+ if (comptime Environment.allow_assert) std.debug.assert(this.lockfile.buffers.dependencies.items.len == this.lockfile.buffers.resolutions.items.len);
if (is_main) {
this.enqueueDependencyWithMainAndSuccessFn(
index,
@@ -1812,15 +1811,15 @@ pub const PackageManager = struct {
) void {
if (Output.isEmojiEnabled()) {
if (is_first) {
- std.mem.copy(u8, &this.progress_name_buf, emoji);
- std.mem.copy(u8, this.progress_name_buf[emoji.len..], name);
+ bun.copy(u8, &this.progress_name_buf, emoji);
+ bun.copy(u8, this.progress_name_buf[emoji.len..], name);
node.name = this.progress_name_buf[0 .. emoji.len + name.len];
} else {
- std.mem.copy(u8, this.progress_name_buf[emoji.len..], name);
+ bun.copy(u8, this.progress_name_buf[emoji.len..], name);
node.name = this.progress_name_buf[0 .. emoji.len + name.len];
}
} else {
- std.mem.copy(u8, &this.progress_name_buf, name);
+ bun.copy(u8, &this.progress_name_buf, name);
node.name = this.progress_name_buf[0..name.len];
}
}
@@ -4256,7 +4255,7 @@ pub const PackageManager = struct {
const len = std.mem.count(u8, native_packages, " ");
if (len > 0) {
var all = try allocator.alloc(PackageNameHash, this.native_bin_link_allowlist.len + len);
- std.mem.copy(PackageNameHash, all, this.native_bin_link_allowlist);
+ bun.copy(PackageNameHash, all, this.native_bin_link_allowlist);
var remain = all[this.native_bin_link_allowlist.len..];
var splitter = std.mem.split(u8, native_packages, " ");
var i: usize = 0;
@@ -4373,7 +4372,7 @@ pub const PackageManager = struct {
if (cli.link_native_bins.len > 0) {
var all = try allocator.alloc(PackageNameHash, this.native_bin_link_allowlist.len + cli.link_native_bins.len);
- std.mem.copy(PackageNameHash, all, this.native_bin_link_allowlist);
+ bun.copy(PackageNameHash, all, this.native_bin_link_allowlist);
var remain = all[this.native_bin_link_allowlist.len..];
for (cli.link_native_bins, 0..) |name, i| {
remain[i] = String.Builder.stringHash(name);
@@ -4527,7 +4526,7 @@ pub const PackageManager = struct {
}
var new_dependencies = try allocator.alloc(G.Property, dependencies.len + remaining - replacing);
- std.mem.copy(G.Property, new_dependencies, dependencies);
+ bun.copy(G.Property, new_dependencies, dependencies);
std.mem.set(G.Property, new_dependencies[dependencies.len..], G.Property{});
outer: for (updates) |*update| {
@@ -4618,7 +4617,7 @@ pub const PackageManager = struct {
current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = JSAst.G.Property.List.init(root_properties) }, logger.Loc.Empty);
} else if (needs_new_dependency_list) {
var root_properties = try allocator.alloc(JSAst.G.Property, current_package_json.data.e_object.properties.len + 1);
- std.mem.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice());
+ bun.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice());
root_properties[root_properties.len - 1] = .{
.key = JSAst.Expr.init(
JSAst.E.String,
@@ -4705,7 +4704,7 @@ pub const PackageManager = struct {
var fs = try Fs.FileSystem.init1(ctx.allocator, null);
var original_cwd = std.mem.trimRight(u8, fs.top_level_dir, "/");
- std.mem.copy(u8, &cwd_buf, original_cwd);
+ bun.copy(u8, &cwd_buf, original_cwd);
// Step 1. Find the nearest package.json directory
//
@@ -4736,7 +4735,7 @@ pub const PackageManager = struct {
};
}
- std.mem.copy(u8, &cwd_buf, original_cwd);
+ bun.copy(u8, &cwd_buf, original_cwd);
cwd_buf[original_cwd.len] = 0;
var real_cwd: [:0]u8 = cwd_buf[0..original_cwd.len :0];
std.os.chdirZ(real_cwd) catch {};
@@ -4749,8 +4748,8 @@ pub const PackageManager = struct {
cwd_buf[fs.top_level_dir.len] = '/';
cwd_buf[fs.top_level_dir.len + 1] = 0;
fs.top_level_dir = cwd_buf[0 .. fs.top_level_dir.len + 1];
- std.mem.copy(u8, &package_json_cwd_buf, fs.top_level_dir);
- std.mem.copy(u8, package_json_cwd_buf[fs.top_level_dir.len..], "package.json");
+ bun.copy(u8, &package_json_cwd_buf, fs.top_level_dir);
+ bun.copy(u8, package_json_cwd_buf[fs.top_level_dir.len..], "package.json");
var entries_option = try fs.fs.readDirectory(fs.top_level_dir, null);
var options = Options{
@@ -5461,7 +5460,7 @@ pub const PackageManager = struct {
buf2[path_.len] = 0;
final_path = buf2[0..path_.len :0];
} else {
- std.mem.copy(u8, &buf, cwd_);
+ bun.copy(u8, &buf, cwd_);
buf[cwd_.len] = 0;
final_path = buf[0..cwd_.len :0];
}
@@ -5980,8 +5979,8 @@ pub const PackageManager = struct {
var cwd = std.fs.cwd();
// This is not exactly correct
var node_modules_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
- std.mem.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str);
- var offset_buf: []u8 = node_modules_buf["node_modules/".len..];
+ bun.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str);
+ var offset_buf = node_modules_buf["node_modules/".len..];
const name_hashes = manager.lockfile.packages.items(.name_hash);
for (updates) |update| {
// If the package no longer exists in the updated lockfile, delete the directory
@@ -5989,7 +5988,7 @@ pub const PackageManager = struct {
// It does not handle nested dependencies
// This is a quick & dirty cleanup intended for when deleting top-level dependencies
if (std.mem.indexOfScalar(PackageNameHash, name_hashes, String.Builder.stringHash(update.name)) == null) {
- std.mem.copy(u8, offset_buf, update.name);
+ bun.copy(u8, offset_buf, update.name);
cwd.deleteTree(node_modules_buf[0 .. "node_modules/".len + update.name.len]) catch {};
}
}
@@ -6005,7 +6004,7 @@ pub const PackageManager = struct {
// any symlinks which we are unable to open are assumed to be dangling
// note that using access won't work here, because access doesn't resolve symlinks
- std.mem.copy(u8, &node_modules_buf, entry.name);
+ bun.copy(u8, &node_modules_buf, entry.name);
node_modules_buf[entry.name.len] = 0;
var buf: [:0]u8 = node_modules_buf[0..entry.name.len :0];
@@ -6134,7 +6133,7 @@ pub const PackageManager = struct {
const alias = this.lockfile.buffers.dependencies.items[dependency_id].name.slice(buf);
const destination_dir_subpath: [:0]u8 = brk: {
- std.mem.copy(u8, &this.destination_dir_subpath_buf, alias);
+ bun.copy(u8, &this.destination_dir_subpath_buf, alias);
this.destination_dir_subpath_buf[alias.len] = 0;
break :brk this.destination_dir_subpath_buf[0..alias.len :0];
};