authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-31 20:49:05 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-31 20:49:05 -07:00
logabb4775126543c1054a05f547884775919f275d0
tree555acd31b39c549d114cdd897c89072121d31c74
parenta1a066da88dab50873a56f0349dc12dc76542077
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

use nfs


2 files changed, 6 insertions(+), 4 deletions(-)

src/lib.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2pub const licenses = @import("licenses-text");2pub const licenses = @import("licenses-text");
3const leven = @import("leven");3const leven = @import("leven");
4const nfs = @import("nfs");
45
5pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {6pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
6 var min: ?usize = null;7 var min: ?usize = null;
...@@ -17,7 +18,7 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {...@@ -17,7 +18,7 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
17 return licenses.spdx[ind.?][0];18 return licenses.spdx[ind.?][0];
18}19}
1920
20pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {21pub fn detectInDir(alloc: std.mem.Allocator, dir: nfs.Dir) !?[]const u8 {
21 const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse22 const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse
22 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse23 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse
23 (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse24 (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse
...@@ -26,11 +27,11 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {...@@ -26,11 +27,11 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
26 return try detect(alloc, b);27 return try detect(alloc, b);
27}28}
2829
29pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 {30pub fn testLicenseFile(alloc: std.mem.Allocator, dir: nfs.Dir, name: [:0]const u8) !?[]const u8 {
30 const file = dir.openFile(name, .{}) catch |err| switch (err) {31 const file = dir.openFile(name, .{}) catch |err| switch (err) {
31 error.FileNotFound => return null,32 error.ENOENT => return null,
32 else => |e| return e,33 else => |e| return e,
33 };34 };
34 defer file.close();35 defer file.close();
35 return try file.reader().readAllAlloc(alloc, 1024 * 1024);36 return try file.readAllAlloc(alloc, 1024 * 1024);
36}37}
zig.mod+1
...@@ -6,5 +6,6 @@ description: Given an input text guess which SPDX license it most likely is an i...@@ -6,5 +6,6 @@ description: Given an input text guess which SPDX license it most likely is an i
6dependencies:6dependencies:
7 - src: git https://github.com/nektro/zig-licenses-text7 - src: git https://github.com/nektro/zig-licenses-text
8 - src: git https://github.com/nektro/zig-leven8 - src: git https://github.com/nektro/zig-leven
9 - src: git https://github.com/nektro/zig-nfs
9root_dependencies:10root_dependencies:
10 - src: git https://github.com/nektro/zig-expect11 - src: git https://github.com/nektro/zig-expect