Skip to content

Commit

Permalink
entry_types: fromPath cross-platform (currently stub on non-linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimschmidt557 committed Jul 23, 2024
1 parent 939065a commit 3ed1a53
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/entry_types.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");

const os = std.os;
const StaticStringMap = std.StaticStringMap;
const File = std.fs.File;
Expand Down Expand Up @@ -112,9 +114,7 @@ pub const EntryType = enum {
return str_type_map.get(entry_type);
}

/// Get the entry type for this path
/// Does not take ownership of the path
pub fn fromPath(path: []const u8) !Self {
fn fromPathLinux(path: []const u8) !Self {
var file = try std.fs.cwd().openFile(path, .{});
defer file.close();

Expand Down Expand Up @@ -158,6 +158,15 @@ pub const EntryType = enum {
return EntryType.Normal;
}
}

/// Get the entry type for this path
/// Does not take ownership of the path
pub fn fromPath(path: []const u8) !Self {
switch (builtin.os.tag) {
.linux => return try Self.fromPathLinux(path),
else => return EntryType.Normal,
}
}
};

test "parse entry types" {
Expand Down

0 comments on commit 3ed1a53

Please sign in to comment.