| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | pub const licenses = @import("licenses-text"); |
| 3 | 3 | const leven = @import("leven"); |
| 4 | const nfs = @import("nfs"); |
| 4 | 5 | |
| 5 | 6 | pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { |
| 6 | 7 | var min: ?usize = null; |
| ... | ... | @@ -17,7 +18,7 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { |
| 17 | 18 | return licenses.spdx[ind.?][0]; |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | | pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { |
| 21 | pub fn detectInDir(alloc: std.mem.Allocator, dir: nfs.Dir) !?[]const u8 { |
| 21 | 22 | const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse |
| 22 | 23 | (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse |
| 23 | 24 | (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 | 27 | return try detect(alloc, b); |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | | pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 { |
| 30 | pub fn testLicenseFile(alloc: std.mem.Allocator, dir: nfs.Dir, name: [:0]const u8) !?[]const u8 { |
| 30 | 31 | const file = dir.openFile(name, .{}) catch |err| switch (err) { |
| 31 | | error.FileNotFound => return null, |
| 32 | error.ENOENT => return null, |
| 32 | 33 | else => |e| return e, |
| 33 | 34 | }; |
| 34 | 35 | defer file.close(); |
| 35 | | return try file.reader().readAllAlloc(alloc, 1024 * 1024); |
| 36 | return try file.readAllAlloc(alloc, 1024 * 1024); |
| 36 | 37 | } |