diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index 129dd659..70ca93a1 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1191,6 +1191,20 @@ pub const Incl = struct { p.incl.clearRetainingCapacity(); return p.setMessage(c.id, "Incl: none"); } + // All checked before any is taken: `-` clears, alone; a directory + // is absolute (or ~) and there. + var check = std.mem.tokenizeAny(u8, typed, " \t"); + while (check.next()) |dir_word| { + var said: [320]u8 = undefined; + const shown = dir_word[0..@min(dir_word.len, 200)]; + if (std.mem.eql(u8, dir_word, "-")) return p.reportFailure(c.id, "Incl: invalid: - clears the list, alone"); + if (dir_word[0] != '/' and dir_word[0] != '~') + return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Incl: invalid directory: {s} is relative", .{shown}) catch "Incl: invalid directory"); + var home_buf: [4096]u8 = undefined; + const expanded = @import("fs.zig").expandHome(dir_word, &home_buf); + if (comptime pardes.hosted) if (@import("fs.zig").localPath(expanded)) |local| if (!exec.isDirectory(local)) + return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Incl: no such directory: {s}", .{shown}) catch "Incl: no such directory"); + } var words = std.mem.tokenizeAny(u8, typed, " \t"); while (words.next()) |dir_word| { var home_buf: [4096]u8 = undefined; |
