diff --git a/src/lib.zig b/src/lib.zig index 74a7a29f7169ac6b435848701a2b74e6182b2810..f6b779dce2cd4a3181d3eeff13baaaf6e086ebee 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -1,6 +1,7 @@ const std = @import("std"); pub const licenses = @import("licenses-text"); const leven = @import("leven"); +const nfs = @import("nfs"); pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { var min: ?usize = null; @@ -17,7 +18,7 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { return licenses.spdx[ind.?][0]; } -pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { +pub fn detectInDir(alloc: std.mem.Allocator, dir: nfs.Dir) !?[]const u8 { const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse @@ -26,11 +27,11 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { return try detect(alloc, b); } -pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 { +pub fn testLicenseFile(alloc: std.mem.Allocator, dir: nfs.Dir, name: [:0]const u8) !?[]const u8 { const file = dir.openFile(name, .{}) catch |err| switch (err) { - error.FileNotFound => return null, + error.ENOENT => return null, else => |e| return e, }; defer file.close(); - return try file.reader().readAllAlloc(alloc, 1024 * 1024); + return try file.readAllAlloc(alloc, 1024 * 1024); } diff --git a/zig.mod b/zig.mod index 0bc65020fe091addb9f3e945dfc8b8233e0a18c7..8fd373e6bbb7d00106bb5bfca41a37a33d1d07b0 100644 --- a/zig.mod +++ b/zig.mod @@ -6,5 +6,6 @@ description: Given an input text guess which SPDX license it most likely is an i dependencies: - src: git https://github.com/nektro/zig-licenses-text - src: git https://github.com/nektro/zig-leven + - src: git https://github.com/nektro/zig-nfs root_dependencies: - src: git https://github.com/nektro/zig-expect