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;
|
var new_dirs: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||||
|
|
||||||
self.snapshots_mutex.lock();
|
self.snapshots_mutex.lock();
|
||||||
|
errdefer self.snapshots_mutex.unlock();
|
||||||
{
|
{
|
||||||
for (current_dirs.items) |name| {
|
for (current_dirs.items) |name| {
|
||||||
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
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| {
|
const gop = self.snapshots.getOrPut(allocator, dir_path) catch |e| {
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
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| {
|
while (cit.next()) |entry| {
|
||||||
if (snapshot.contains(entry.key_ptr.*)) continue;
|
if (snapshot.contains(entry.key_ptr.*)) continue;
|
||||||
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
snapshot.put(allocator, owned, {}) catch |e| {
|
snapshot.put(allocator, owned, {}) catch |e| {
|
||||||
allocator.free(owned);
|
allocator.free(owned);
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
try to_create.append(tmp, owned);
|
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;
|
var new_dirs: std.ArrayListUnmanaged([]const u8) = .empty;
|
||||||
|
|
||||||
self.snapshots_mutex.lock();
|
self.snapshots_mutex.lock();
|
||||||
|
errdefer self.snapshots_mutex.unlock();
|
||||||
{
|
{
|
||||||
for (current_dirs.items) |name| {
|
for (current_dirs.items) |name| {
|
||||||
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
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| {
|
const gop = self.snapshots.getOrPut(allocator, dir_path) catch |e| {
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
if (!gop.found_existing) gop.value_ptr.* = .empty;
|
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 {
|
} else {
|
||||||
// New file — add to snapshot and to_create list.
|
// New file — add to snapshot and to_create list.
|
||||||
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
const owned = allocator.dupe(u8, entry.key_ptr.*) catch |e| {
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
snapshot.put(allocator, owned, entry.value_ptr.*) catch |e| {
|
snapshot.put(allocator, owned, entry.value_ptr.*) catch |e| {
|
||||||
allocator.free(owned);
|
allocator.free(owned);
|
||||||
self.snapshots_mutex.unlock();
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
try to_create.append(tmp, owned); // borrow from snapshot
|
try to_create.append(tmp, owned); // borrow from snapshot
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue