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 @@...@@ -1,7 +1,6 @@
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 fscheck = @import("fs-check");
54
6pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {5pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
7 var min: ?usize = null;6 var min: ?usize = null;
...@@ -20,21 +19,19 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {...@@ -20,21 +19,19 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
20}19}
2120
22pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {21pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
23 const lic_filename = (try testLicenseFile(dir, "LICENSE")) orelse22 const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse
24 (try testLicenseFile(dir, "LICENSE.md")) orelse23 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse
25 null;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);
31 defer alloc.free(b);26 defer alloc.free(b);
32 return try detect(alloc, b);27 return try detect(alloc, b);
33}28}
3429
35//30pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 {
36//31 const file = dir.openFile(name, .{}) catch |err| switch (err) {
3732 error.FileNotFound => return null,
38pub fn testLicenseFile(dir: std.fs.Dir, name: []const u8) !?[]const u8 {33 else => |e| return e,
39 return if (try fscheck.doesFileExist(dir, name)) name else null;34 };
35 defer file.close();
36 return try file.reader().readAllAlloc(alloc, 1024 * 1024);
40}37}
zig.mod-1
...@@ -6,4 +6,3 @@ description: Given an input text guess which SPDX license it most likely is an i...@@ -6,4 +6,3 @@ 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-fs-check