Skip to content

Commit

Permalink
fix hidden specs on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Nov 30, 2024
1 parent fa03e7a commit 2c5c970
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/__tests__/hidden.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from "@jest/globals";
import { execSync } from "node:child_process";
import fs from "node:fs/promises";
import path from "node:path";
Expand Down Expand Up @@ -304,7 +305,9 @@ describe("hidden file tests", () => {
});

// Test "all" method
const allResult = await setHidden(testFile, true, "all");
const allResult = await setHidden(dotPrefixResult.pathname, true, "all");

expect(allResult.pathname).toEqual(dotPrefixResult.pathname);

if (isWindows) {
expect(allResult.actions).toEqual({
Expand All @@ -313,7 +316,7 @@ describe("hidden file tests", () => {
});
} else {
expect(allResult.actions).toEqual({
dotPrefix: true,
dotPrefix: false,
systemFlag: process.platform === "darwin",
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/hidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export type HideMethod = "dotPrefix" | "systemFlag" | "all" | "auto";

export async function setHidden(
pathname: string,
hidden: boolean,
hide: boolean,
method: HideMethod,
nativeFn: NativeBindingsFn,
) {
Expand All @@ -174,21 +174,21 @@ export async function setHidden(
systemFlag: false,
};

let handled = false;
let hidden = false;

if (LocalSupport.dotPrefix && ["auto", "all", "dotPrefix"].includes(method)) {
if (isPosixHidden(pathname) !== hidden) {
pathname = await setHiddenPosix(pathname, hidden);
if (isPosixHidden(pathname) !== hide) {
pathname = await setHiddenPosix(pathname, hide);
actions.dotPrefix = true;
}
handled = true;
hidden = true;
}

if (
LocalSupport.systemFlag &&
(["all", "systemFlag"].includes(method) || (!handled && method === "auto"))
(["all", "systemFlag"].includes(method) || (!hidden && method === "auto"))
) {
await (await nativeFn()).setHidden(pathname, hidden);
await (await nativeFn()).setHidden(pathname, hide);
actions.systemFlag = true;
}

Expand Down

0 comments on commit 2c5c970

Please sign in to comment.