authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-05 18:33:36 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-05 18:33:36 -08:00
logde5c285d999eea68b9189b48bb000243fef0a689
tree27396e7810ab56303285da1086964f7e8f910223
parent60750ad11a077158240c59d5f728c37abbf458a6

remove use of fs-check dependency


2 files changed, 10 insertions(+), 14 deletions(-)

src/lib.zig+10-13
......@@ -1,7 +1,6 @@
11const std = @import("std");
22pub const licenses = @import("licenses-text");
33const leven = @import("leven");
4const fscheck = @import("fs-check");
54
65pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
76 var min: ?usize = null;
......@@ -20,21 +19,19 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
2019}
2120
2221pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
23 const lic_filename = (try testLicenseFile(dir, "LICENSE")) orelse
24 (try testLicenseFile(dir, "LICENSE.md")) orelse
25 null;
22 const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse
23 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse
24 return null;
2625
27 if (lic_filename == null) return null;
28 const f = try dir.openFile(lic_filename.?, .{});
29 defer f.close();
30 const b = try f.reader().readAllAlloc(alloc, 1024 * 1024);
3126 defer alloc.free(b);
3227 return try detect(alloc, b);
3328}
3429
35//
36//
37
38pub fn testLicenseFile(dir: std.fs.Dir, name: []const u8) !?[]const u8 {
39 return if (try fscheck.doesFileExist(dir, name)) name else null;
30pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 {
31 const file = dir.openFile(name, .{}) catch |err| switch (err) {
32 error.FileNotFound => return null,
33 else => |e| return e,
34 };
35 defer file.close();
36 return try file.reader().readAllAlloc(alloc, 1024 * 1024);
4037}
zig.mod-1
......@@ -6,4 +6,3 @@ description: Given an input text guess which SPDX license it most likely is an i
66dependencies:
77 - src: git https://github.com/nektro/zig-licenses-text
88 - src: git https://github.com/nektro/zig-leven
9 - src: git https://github.com/nektro/zig-fs-check