summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Db.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Db.zig b/src/Db.zig
index e5364b44..73e6480a 100644
--- a/src/Db.zig
+++ b/src/Db.zig
@@ -361,6 +361,10 @@ fn importRecent(p: *Pardes, dir: []const u8) void {
const gpa = p.recentGpa();
const io = ioOf();
var path_buf: [4200]u8 = undefined;
+ if (dir.len + "/recent".len >= std.Io.Dir.max_path_bytes) {
+ var said: [160]u8 = undefined;
+ return p.setMessage(p.view().active, std.fmt.bufPrint(&said, "Recent: the files before the state file were not read: their directory's path is {d} bytes, too long", .{dir.len}) catch unreachable); // a number fits 160
+ }
pardes.turn.yield();
const listed = std.Io.Dir.cwd().readFileAlloc(io, std.fmt.bufPrint(&path_buf, "{s}/recent", .{dir}) catch "", gpa, .limited(recent_max)) catch null;
const logged = if (listed == null) std.Io.Dir.cwd().readFileAlloc(io, std.fmt.bufPrint(&path_buf, "{s}/store", .{dir}) catch "", gpa, .limited(128 << 20)) catch null else null;
@@ -1397,6 +1401,19 @@ test "state file: Recent is read once from the file it replaced, else from the s
try testing.expectEqual(@as(u32, 9), b.recent.entries.items[0].line);
try testing.expectEqualStrings("/w/both.zig", b.recent.entries.items[1].path);
}
+ // A directory whose path is past the room for its files' names: none
+ // read, and said so.
+ {
+ try tmp.dir.createDirPath(testing.io, "c");
+ var long: [4200]u8 = undefined;
+ @memset(&long, 'd');
+ long[0] = '/';
+ const c = try window(try std.fmt.bufPrint(&buf[2], "{s}/c", .{dir}), &long);
+ defer c.deinit();
+ try testing.expectEqual(@as(usize, 0), c.recent.entries.items.len);
+ const pane = c.panes[c.view().active].?;
+ try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "Recent: the files before the state file were not read") != null);
+ }
// Both left where they were.
_ = try tmp.dir.statFile(testing.io, "old/recent", .{});
_ = try tmp.dir.statFile(testing.io, "older/store", .{});