From de5c285d999eea68b9189b48bb000243fef0a689 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 5 Feb 2022 18:33:36 -0800 Subject: [PATCH] remove use of fs-check dependency --- src/lib.zig | 23 ++++++++++------------- zig.mod | 1 - 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/lib.zig b/src/lib.zig index f07a93746849205e6e6f9f83309101ba151ae723..09b0e2b80883b82af53763f9ad7285c690cafbe1 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -1,7 +1,6 @@ const std = @import("std"); pub const licenses = @import("licenses-text"); const leven = @import("leven"); -const fscheck = @import("fs-check"); pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { var min: ?usize = null; @@ -20,21 +19,19 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { } pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { - const lic_filename = (try testLicenseFile(dir, "LICENSE")) orelse - (try testLicenseFile(dir, "LICENSE.md")) orelse - null; + const b = (try testLicenseFile(alloc, dir, "LICENSE")) orelse + (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse + return null; - if (lic_filename == null) return null; - const f = try dir.openFile(lic_filename.?, .{}); - defer f.close(); - const b = try f.reader().readAllAlloc(alloc, 1024 * 1024); defer alloc.free(b); return try detect(alloc, b); } -// -// - -pub fn testLicenseFile(dir: std.fs.Dir, name: []const u8) !?[]const u8 { - return if (try fscheck.doesFileExist(dir, name)) name else null; +pub fn testLicenseFile(alloc: std.mem.Allocator, dir: std.fs.Dir, name: []const u8) !?[]const u8 { + const file = dir.openFile(name, .{}) catch |err| switch (err) { + error.FileNotFound => return null, + else => |e| return e, + }; + defer file.close(); + return try file.reader().readAllAlloc(alloc, 1024 * 1024); } diff --git a/zig.mod b/zig.mod index 35ec68ef1b8618a57b703a7e2245f188b9edc744..46ba11e6430aae87cd4c383d187c78ed424459c8 100644 --- a/zig.mod +++ b/zig.mod @@ -6,4 +6,3 @@ 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-fs-check -- 2.54.0