Add main.zig
This commit is contained in:
45
main.zig
Normal file
45
main.zig
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
// using zig-0.15.2
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const File = struct {
|
||||||
|
path: [:0]u8,
|
||||||
|
size: u64,
|
||||||
|
duplicate_size: ?usize = null,
|
||||||
|
hash: ?u256 = null,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
const allocator = gpa.allocator();
|
||||||
|
defer _ = gpa.deinit();
|
||||||
|
|
||||||
|
var list: std.ArrayList(File) = .empty;
|
||||||
|
defer list.deinit(allocator);
|
||||||
|
var args_it = std.process.args();
|
||||||
|
_ = args_it.next(); // skip program name
|
||||||
|
while (args_it.next()) |arg| {
|
||||||
|
const dir = try std.fs.cwd().openDir(arg, .{ .iterate = true });
|
||||||
|
var walker = try dir.walk(allocator);
|
||||||
|
defer walker.deinit();
|
||||||
|
while (try walker.next()) |entry| {
|
||||||
|
if (entry.kind == .file) {
|
||||||
|
const stat = try entry.dir.statFile(entry.basename);
|
||||||
|
try list.append(allocator, .{
|
||||||
|
.path = try allocator.dupeZ(u8, entry.path),
|
||||||
|
.size = stat.size,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (list.items, 0..) |*item, idx| {
|
||||||
|
for (list.items) |*item2| {
|
||||||
|
if (item.size == item2.size) {
|
||||||
|
item.duplicate_size = idx;
|
||||||
|
item2.duplicate_size = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std.debug.print("path: {s}, size {}\n", .{ item.path, item.size });
|
||||||
|
allocator.free(item.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user