Package.Fetch: fix inclusions not working for directories

Oops, the loop was checking the wrong variable! Added a unit test.
This commit is contained in:
Andrew Kelley 2023-10-09 20:48:39 -07:00
parent aaf46187ab
commit 2ca7cc46c4

View File

@ -1510,12 +1510,22 @@ const Filter = struct {
// Check if any included paths are parent directories of sub_path.
var dirname = sub_path;
while (std.fs.path.dirname(dirname)) |next_dirname| {
if (self.include_paths.contains(sub_path)) return true;
if (self.include_paths.contains(next_dirname)) return true;
dirname = next_dirname;
}
return false;
}
test includePath {
const gpa = std.testing.allocator;
var filter: Filter = .{};
defer filter.include_paths.deinit(gpa);
try filter.include_paths.put(gpa, "src", {});
try std.testing.expect(filter.includePath("src/core/unix/SDL_poll.c"));
try std.testing.expect(!filter.includePath(".gitignore"));
}
};
pub fn depDigest(
@ -1556,3 +1566,7 @@ const git = @import("Fetch/git.zig");
const Package = @import("../Package.zig");
const Manifest = Package.Manifest;
const ErrorBundle = std.zig.ErrorBundle;
test {
_ = Filter;
}