GeezerVison is showing github.com — Merge pull request #352 from shuv1337/fix/linux-deb-write-bits · shuv1337/s2code@2de863c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: knip.jsonc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | // Knip loads its preprocessor through a CLI option; native verification and | 21 | 21 | // worktree setup (from t3.json) run directly. release-desktop.yml bundles the | 22 | 22 | // Windows verify script with esbuild through a path knip does not trace, | 23 | | - // electron-builder loads the macOS signer by path, and mobile-e2e.ts runs | | 23 | + // electron-builder loads the macOS signer and the Linux afterPack hook by path, and mobile-e2e.ts runs | 24 | 24 | // agent-device's CLI by path, and mobile-behavior.ts spawns its runner by path. | 25 | 25 | // release-desktop.yml runs the desktop launch check through xvfb-run, which knip | 26 | 26 | // does not trace. release-smoke.ts runs the nightly resolver by path. | 27 | 27 | "entry": [ | 28 | 28 | // These fixture scripts are injected into a browser page by path. | 29 | 29 | "fixtures/*/*.js", | 30 | 30 | "knip-schemas.ts", | | 31 | + "linux-after-pack.ts", | 31 | 32 | "mobile-behavior/run.ts", | 32 | 33 | "mobile-native-client.ts", | 33 | 34 | "resolve-nightly-release.ts", | |
Collapse file Copy file name to clipboardExpand all lines: scripts/build-desktop-artifact.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3188,6 +3188,7 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* ( | 3188 | 3188 | buildConfig.toolsets = { appimage: "1.0.3" }; | 3189 | 3189 | const path = yield* Path.Path; | 3190 | 3190 | const repoRoot = yield* RepoRoot; | | 3191 | + buildConfig.afterPack = path.join(repoRoot, "scripts/linux-after-pack.ts"); | 3191 | 3192 | buildConfig.linux = { | 3192 | 3193 | target: target === "AppImage" ? [target, "deb"] : [target], | 3193 | 3194 | executableName: identity.executableName, | |
Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// @effect-diagnostics nodeBuiltinImport:off - Applies real file modes in a temporary app folder. | | 2 | +import * as HostProcess from "@t3tools/shared/HostProcess"; | | 3 | +import * as NodeFSP from "node:fs/promises"; | | 4 | +import * as NodeOS from "node:os"; | | 5 | +import * as NodePath from "node:path"; | | 6 | +import { describe, expect, it } from "vite-plus/test"; | | 7 | + | | 8 | +import { removeSharedWriteAccess } from "./linux-after-pack.ts"; | | 9 | + | | 10 | +describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("removeSharedWriteAccess", () => { | | 11 | + it("removes group and other write access from the packed app only", async () => { | | 12 | + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-after-pack-")); | | 13 | + try { | | 14 | + const appOutDir = NodePath.join(root, "app"); | | 15 | + const modes = { | | 16 | + "app/t3code": [0o777, 0o755], | | 17 | + "app/resources.pak": [0o666, 0o644], | | 18 | + "app/chrome-sandbox": [0o4777, 0o4755], | | 19 | + "app/resources/app.asar": [0o644, 0o644], | | 20 | + "outside/file": [0o666, 0o666], | | 21 | + } as const; | | 22 | + await NodeFSP.mkdir(NodePath.join(appOutDir, "resources"), { recursive: true }); | | 23 | + await NodeFSP.mkdir(NodePath.join(root, "outside")); | | 24 | + for (const [file, [before]] of Object.entries(modes)) { | | 25 | + await NodeFSP.writeFile(NodePath.join(root, file), ""); | | 26 | + await NodeFSP.chmod(NodePath.join(root, file), before); | | 27 | + } | | 28 | + await NodeFSP.chmod(NodePath.join(appOutDir, "resources"), 0o777); | | 29 | + await NodeFSP.symlink("../outside", NodePath.join(appOutDir, "linked-dir")); | | 30 | + | | 31 | + await removeSharedWriteAccess(appOutDir); | | 32 | + | | 33 | + for (const [file, [, after]] of Object.entries(modes)) { | | 34 | + const { mode } = await NodeFSP.stat(NodePath.join(root, file)); | | 35 | + expect([file, mode & 0o7777]).toEqual([file, after]); | | 36 | + } | | 37 | + const { mode: resourcesMode } = await NodeFSP.stat(NodePath.join(appOutDir, "resources")); | | 38 | + expect(resourcesMode & 0o7777).toBe(0o755); | | 39 | + } finally { | | 40 | + await NodeFSP.rm(root, { recursive: true, force: true }); | | 41 | + } | | 42 | + }); | | 43 | +}); |
Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// @effect-diagnostics nodeBuiltinImport:off | | 2 | +import * as NodeFSP from "node:fs/promises"; | | 3 | +import * as NodePath from "node:path"; | | 4 | + | | 5 | +interface AfterPackContext { | | 6 | + readonly appOutDir: string; | | 7 | +} | | 8 | + | | 9 | +// Electron's Linux zips can ship world-writable files (44.10.0 has 0777 binaries), and | | 10 | +// electron-builder copies zip modes verbatim into the .deb and AppImage. | | 11 | +export default async function afterPack(context: AfterPackContext): Promise<void> { | | 12 | + await removeSharedWriteAccess(context.appOutDir); | | 13 | +} | | 14 | + | | 15 | +// Walks by hand: recursive readdir follows directory symlinks out of the app folder. | | 16 | +export async function removeSharedWriteAccess(path: string): Promise<void> { | | 17 | + const stats = await NodeFSP.lstat(path); | | 18 | + if (stats.isSymbolicLink()) return; | | 19 | + if (stats.mode & 0o022) await NodeFSP.chmod(path, stats.mode & 0o7755); | | 20 | + if (!stats.isDirectory()) return; | | 21 | + for (const entry of await NodeFSP.readdir(path)) { | | 22 | + await removeSharedWriteAccess(NodePath.join(path, entry)); | | 23 | + } | | 24 | +} |
|