Merge pull request #487 from lightpanda-io/mkdir_p_app_path

Use makePath to create any missing intermediate directories for app dir
This commit is contained in:
Pierre Tachoire
2025-03-23 10:48:55 +01:00
committed by GitHub
2 changed files with 10 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
return null; return null;
}; };
std.fs.makeDirAbsolute(app_dir_path) catch |err| switch (err) { std.fs.cwd().makePath(app_dir_path) catch |err| switch (err) {
error.PathAlreadyExists => return app_dir_path, error.PathAlreadyExists => return app_dir_path,
else => { else => {
allocator.free(app_dir_path); allocator.free(app_dir_path);

View File

@@ -60,7 +60,11 @@ fn TelemetryT(comptime P: type) type {
} }
fn getOrCreateId(app_dir_path_: ?[]const u8) ?[36]u8 { fn getOrCreateId(app_dir_path_: ?[]const u8) ?[36]u8 {
const app_dir_path = app_dir_path_ orelse return null; const app_dir_path = app_dir_path_ orelse {
var id: [36]u8 = undefined;
uuidv4(&id);
return id;
};
var buf: [37]u8 = undefined; var buf: [37]u8 = undefined;
var dir = std.fs.openDirAbsolute(app_dir_path, .{}) catch |err| { var dir = std.fs.openDirAbsolute(app_dir_path, .{}) catch |err| {
@@ -146,6 +150,10 @@ test "telemetry: getOrCreateId" {
std.fs.cwd().deleteFile("/tmp/" ++ IID_FILE) catch {}; std.fs.cwd().deleteFile("/tmp/" ++ IID_FILE) catch {};
const id3 = getOrCreateId("/tmp/").?; const id3 = getOrCreateId("/tmp/").?;
try testing.expectEqual(false, std.mem.eql(u8, &id1, &id3)); try testing.expectEqual(false, std.mem.eql(u8, &id1, &id3));
const id4 = getOrCreateId(null).?;
try testing.expectEqual(false, std.mem.eql(u8, &id1, &id4));
try testing.expectEqual(false, std.mem.eql(u8, &id3, &id4));
} }
test "telemetry: sends event to provider" { test "telemetry: sends event to provider" {