Skip to content

Commit 4c68150

Browse files
Merge pull request #487 from lightpanda-io/mkdir_p_app_path
Use makePath to create any missing intermediate directories for app dir
2 parents 20160cb + 3d6dd06 commit 4c68150

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/app.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
6767
return null;
6868
};
6969

70-
std.fs.makeDirAbsolute(app_dir_path) catch |err| switch (err) {
70+
std.fs.cwd().makePath(app_dir_path) catch |err| switch (err) {
7171
error.PathAlreadyExists => return app_dir_path,
7272
else => {
7373
allocator.free(app_dir_path);

src/telemetry/telemetry.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ fn TelemetryT(comptime P: type) type {
6060
}
6161

6262
fn getOrCreateId(app_dir_path_: ?[]const u8) ?[36]u8 {
63-
const app_dir_path = app_dir_path_ orelse return null;
63+
const app_dir_path = app_dir_path_ orelse {
64+
var id: [36]u8 = undefined;
65+
uuidv4(&id);
66+
return id;
67+
};
6468

6569
var buf: [37]u8 = undefined;
6670
var dir = std.fs.openDirAbsolute(app_dir_path, .{}) catch |err| {
@@ -146,6 +150,10 @@ test "telemetry: getOrCreateId" {
146150
std.fs.cwd().deleteFile("/tmp/" ++ IID_FILE) catch {};
147151
const id3 = getOrCreateId("/tmp/").?;
148152
try testing.expectEqual(false, std.mem.eql(u8, &id1, &id3));
153+
154+
const id4 = getOrCreateId(null).?;
155+
try testing.expectEqual(false, std.mem.eql(u8, &id1, &id4));
156+
try testing.expectEqual(false, std.mem.eql(u8, &id3, &id4));
149157
}
150158

151159
test "telemetry: sends event to provider" {

0 commit comments

Comments
 (0)