Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/copy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn copyDir(

pub fn copy(io: Io, alloc: std.mem.Allocator, options: *const ProgramOptions) CopyError!void {
const resolved = cfile.resolveCopyTarget(io, alloc, options.source, options.dest) catch |err| switch (err) {
error.ResolveSameDir => return,
error.ResolveSamePath => return,
else => return err,
};
defer resolved.deinit(alloc);
Expand Down
11 changes: 6 additions & 5 deletions src/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ pub const CopyTargetInfo = struct {

const ResolveError = error{
SourceLocationInvalid,
DestLocationInvalid,
ResolveInvalidFileToDir,
ResolveInvalidDirToFile,
ResolveSameDir,
ResolveSamePath,
};

pub const ResolveTargetError = ResolveError || PathStatError || Allocator.Error || Dir.RealPathFileAllocError;
Expand Down Expand Up @@ -105,7 +106,7 @@ pub fn resolveCopyTarget(
const dest_stat = pathStat(cwd, io, dest) catch |err| switch (err) {
error.StatKindNotSupported => {
std.log.err("Dest file kind not supported: '{s}'", .{dest});
return error.SourceLocationInvalid;
return error.DestLocationInvalid;
},
else => return err,
};
Expand All @@ -122,7 +123,7 @@ pub fn resolveCopyTarget(
const norm_dest = try cwd.realPathFileAlloc(io, dest, alloc);
defer alloc.free(norm_dest);
if (std.mem.eql(u8, norm_source, norm_dest)) {
return error.ResolveSameDir;
return error.ResolveSamePath;
}
}
return .{
Expand Down Expand Up @@ -161,7 +162,7 @@ pub fn resolveCopyTarget(
defer alloc.free(norm_dest);
if (std.mem.eql(u8, norm_source, norm_dest)) {
alloc.free(final_dest);
return error.ResolveSameDir;
return error.ResolveSamePath;
}
}

Expand All @@ -183,7 +184,7 @@ pub fn resolveCopyTarget(
const norm_dest = try cwd.realPathFileAlloc(io, dest, alloc);
defer alloc.free(norm_dest);
if (std.mem.eql(u8, norm_source, norm_dest)) {
return error.ResolveSameDir;
return error.ResolveSamePath;
}
}

Expand Down
55 changes: 27 additions & 28 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ fn runCopy(io: Io, arena: std.mem.Allocator, options: *const cp.args.ProgramOpti

cp.copy.copy(io, arena, options) catch |err| {
switch (err) {
error.ResolveSameDir => {},
error.ResolveSamePath => {},
error.SourceLocationInvalid => std.log.err("cp: cannot stat '{s}': No such file or directory", .{options.source}),
error.DestLocationInvalid => std.log.err("cp: cannot stat '{s}': unsupported file type", .{options.dest}),
error.ResolveInvalidFileToDir => std.log.err("cp: cannot copy '{s}' to non-existing directory '{s}'", .{ options.source, options.dest }),
error.ResolveInvalidDirToFile => std.log.err("cp: cannot overwrite non-directory '{s}' with directory '{s}'", .{ options.dest, options.source }),
error.FileNoForce => std.log.err("cp: '{s}' already exists, use -f to overwrite", .{options.dest}),
Expand Down Expand Up @@ -55,33 +56,31 @@ pub fn main(init: std.process.Init) !void {
options.jobs = jobs_info.resolved_jobs;
if (options.verbose) jobs_info.log("jobs");

if (options.backend == .evented) {
// FIXME: (¬`‸´¬) Uring.zig error set bug in zig 0.16.0-dev.3091
// Hope this gets through: https://codeberg.org/ziglang/zig/pulls/31764
switch (options.backend) {
.evented => {
// FIXME: (¬`‸´¬) Uring.zig error set bug in zig 0.16.0-dev.3091
// Hope this gets through: https://codeberg.org/ziglang/zig/pulls/31764

// var evented: Io.Evented = undefined;
// evented.init(init.gpa, .{}) catch |err| {
// std.log.err("cp: failed to init evented backend: {s}", .{@errorName(err)});
// return err;
// };
// defer evented.deinit();
// return runCopy(evented.io(), arena, &options);
std.log.err("cp: evented backend is disabled (Uring.zig error set bug in this zig version)", .{});
return;
}

if (options.backend == .single) {
var single: Io.Threaded = .init_single_threaded;
return runCopy(single.io(), arena, &options);
// var evented: Io.Evented = undefined;
// evented.init(init.gpa, .{}) catch |err| {
// std.log.err("cp: failed to init evented backend: {s}", .{@errorName(err)});
// return err;
// };
// defer evented.deinit();
// return runCopy(evented.io(), arena, &options);
std.log.err("cp: evented backend is disabled (Uring.zig error set bug in this zig version)", .{});
return;
},
.single => {
var single: Io.Threaded = .init_single_threaded;
return runCopy(single.io(), arena, &options);
},
.threaded => {
var threaded: Io.Threaded = Io.Threaded.init(init.gpa, .{
.async_limit = .limited(options.jobs),
});
defer threaded.deinit();
return runCopy(threaded.io(), arena, &options);
},
}

if (options.backend == .threaded) {
var threaded: Io.Threaded = Io.Threaded.init(init.gpa, .{
.async_limit = .limited(options.jobs),
});
defer threaded.deinit();
return runCopy(threaded.io(), arena, &options);
}

unreachable;
}
Loading