From 3ed1a53da305e1cb88dfa1d8f42405d465a875a3 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Tue, 23 Jul 2024 22:33:39 +0200 Subject: [PATCH] entry_types: fromPath cross-platform (currently stub on non-linux) --- src/entry_types.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/entry_types.zig b/src/entry_types.zig index 6d7b4de..f435ac6 100644 --- a/src/entry_types.zig +++ b/src/entry_types.zig @@ -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; @@ -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(); @@ -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" {