fix(kqueue): make sure we release snapshots_mutex on errors
This commit is contained in:
parent
338c8460ff
commit
ae091a5e35
2 changed files with 2 additions and 6 deletions
|
|
@ -186,6 +186,7 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
var new_dirs: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||
|
||||
self.snapshots_mutex.lock();
|
||||
errdefer self.snapshots_mutex.unlock();
|
||||
{
|
||||
for (current_dirs.items) |name| {
|
||||
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
|
|
@ -197,7 +198,6 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
}
|
||||
|
||||
const gop = self.snapshots.getOrPut(allocator, dir_path) catch |e| {
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
||||
|
|
@ -207,12 +207,10 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
while (cit.next()) |entry| {
|
||||
if (snapshot.contains(entry.key_ptr.*)) continue;
|
||||
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
snapshot.put(allocator, owned, {}) catch |e| {
|
||||
allocator.free(owned);
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
try to_create.append(tmp, owned);
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
var new_dirs: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||
|
||||
self.snapshots_mutex.lock();
|
||||
errdefer self.snapshots_mutex.unlock();
|
||||
{
|
||||
for (current_dirs.items) |name| {
|
||||
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
|
|
@ -191,7 +192,6 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
}
|
||||
|
||||
const gop = self.snapshots.getOrPut(allocator, dir_path) catch |e| {
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
||||
|
|
@ -208,12 +208,10 @@ fn scan_dir(self: *@This(), allocator: std.mem.Allocator, dir_path: []const u8)
|
|||
} else {
|
||||
// New file — add to snapshot and to_create list.
|
||||
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
snapshot.put(allocator, owned, entry.value_ptr.*) catch |e| {
|
||||
allocator.free(owned);
|
||||
self.snapshots_mutex.unlock();
|
||||
return e;
|
||||
};
|
||||
try to_create.append(tmp, owned); // borrow from snapshot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue