From 1f1cc286cafb44d66f42a57ff0db99860dbe1311 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Tue, 1 Oct 2024 11:00:27 -0700 Subject: [PATCH] Don't convert dotfiles to ZON, which may include editor configurations. (#734) * Don't convert dotfiles, which may include editor configurations. This means that configurations specific to this workspace in editors don't get overwritten, which prevents accidental formatting errors whenever the game is tested. * Fix accidental formatting change * Use the syntax sugar * Update main.zig --- src/main.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.zig b/src/main.zig index b698d0b38..dc84ed1a0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -403,7 +403,26 @@ fn isValidIdentifierName(str: []const u8) bool { // TODO: Remove after #480 return true; } +fn isHiddenOrParentHiddenPosix(path: []const u8) bool { + var iter = std.fs.path.componentIterator(path) catch |err| { + std.log.err("Cannot iterate on path {s}: {s}!", .{path, @errorName(err)}); + return false; + }; + while (iter.next()) |component| { + if (std.mem.eql(u8, component.name, ".") or std.mem.eql(u8, component.name, "..")) { + continue; + } + if (component.name.len > 0 and component.name[0] == '.') { + return true; + } + } + return false; +} pub fn convertJsonToZon(jsonPath: []const u8) void { // TODO: Remove after #480 + if (isHiddenOrParentHiddenPosix(jsonPath)) { + std.log.info("NOT converting {s}.", .{jsonPath}); + return; + } std.log.info("Converting {s}:", .{jsonPath}); const jsonString = files.read(stackAllocator, jsonPath) catch |err| { std.log.err("Could convert file {s}: {s}", .{jsonPath, @errorName(err)});