adoor 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +2 -2
- package/dist/adoor.mjs +105 -84
- package/native/LICENSE +662 -0
- package/native/README.md +12 -0
- package/native/darwin/ADoorService.app/Contents/Info.plist +57 -0
- package/native/darwin/ADoorService.app/Contents/MacOS/ADoorService +0 -0
- package/native/darwin/ADoorService.app/Contents/PkgInfo +1 -0
- package/native/darwin/ADoorService.app/Contents/_CodeSignature/CodeResources +123 -0
- package/native/darwin/ADoorService.app/Contents/embedded.provisionprofile +0 -0
- package/native/source/Package.swift +6 -0
- package/native/source/sdk/LICENSE +21 -0
- package/native/source/sdk/Package.swift +14 -0
- package/native/source/sdk/Sources/ADoor/AdoorClient.swift +270 -0
- package/native/source/sdk/Sources/ADoor/AdoorError.swift +60 -0
- package/native/source/sdk/Sources/ADoor/Changes.swift +202 -0
- package/native/source/sdk/Sources/ADoor/DesktopSessionState.swift +73 -0
- package/native/source/sdk/Sources/ADoor/DeviceFlow.swift +70 -0
- package/native/source/sdk/Sources/ADoor/FolderCatalog.swift +49 -0
- package/native/source/sdk/Sources/ADoor/JSONValue.swift +70 -0
- package/native/source/sdk/Sources/ADoor/LocalStore.swift +474 -0
- package/native/source/sdk/Sources/ADoor/Models.swift +146 -0
- package/native/source/sdk/Sources/ADoor/MountModel.swift +896 -0
- package/native/source/sdk/Sources/ADoor/OAuth.swift +225 -0
- package/native/source/sdk/Sources/ADoor/Provider.swift +211 -0
- package/native/source/sdk/Sources/ADoor/Storage.swift +41 -0
- package/native/source/sdk/Sources/ADoor/SyncTree.swift +501 -0
- package/native/source/sdk/Sources/ADoor/Trash.swift +283 -0
- package/native/source/sdk/Tests/ADoorTests/ADoorTests.swift +182 -0
- package/native/source/sdk/Tests/ADoorTests/DesktopSessionStateTests.swift +46 -0
- package/native/source/sdk/Tests/ADoorTests/MountTests.swift +560 -0
- package/native/source/sdk/Tests/ADoorTests/RegressionTests.swift +360 -0
- package/native/source/service/DesktopSession.swift +241 -0
- package/native/source/service/DeviceClient.swift +53 -0
- package/native/source/service/Domains.swift +182 -0
- package/native/source/service/FolderRefresh.swift +37 -0
- package/native/source/service/KeychainStore.swift +74 -0
- package/native/source/service/LocalSessionSocket.swift +142 -0
- package/native/source/service/ServiceMain.swift +14 -0
- package/native/source/service/ServiceMounts.swift +34 -0
- package/package.json +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
macOS includes a signed, independent background service. The CLI can install and start it without the GUI; the Mac app joins the same session. Profiles remain in Keychain, and closing the window or quitting the GUI does not disconnect the CLI. The Mac app and File Provider extension are still needed for Finder mounts.
|
|
6
|
+
|
|
3
7
|
## 0.1.0
|
|
4
8
|
|
|
5
9
|
First npm command release as `adoor`, runnable with `npx adoor`. Hosted sign-in is the default. Includes scoped profiles, file push/pull, database and access commands, and shared session support for the matching Mac app. Checkout-only and unfinished bridge/copy commands are listed in the README.
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ To install the command:
|
|
|
16
16
|
npm install --global adoor
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
The CLI runs without the Mac app. It supports login, scoped profiles, database commands, and file push/pull. Finder mounts require ADoor for Mac and its enabled File Provider extension; Linux mounts require FUSE.
|
|
19
|
+
The CLI runs without the Mac app. It supports login, scoped profiles, database commands, and file push/pull. Finder mounts require ADoor for Mac and its enabled File Provider extension; Linux mounts require FUSE. On macOS 14 or newer, the CLI includes a signed background service and starts it independently of the GUI. The matching Mac app joins that same service, with profiles in Keychain. Explicit `STORE_CONFIG` files remain independent unless `ADOOR_DESKTOP_SESSION=1` is set. `ADOOR_DESKTOP_SESSION=0` selects file-backed CLI profiles.
|
|
20
20
|
|
|
21
21
|
For example, with file access approved for the target folder:
|
|
22
22
|
|
|
@@ -49,4 +49,4 @@ Checkout commands such as `schema`, `history`, and `access` run the existing CLI
|
|
|
49
49
|
|
|
50
50
|
On Linux, `adoor mount acme/design ./assets` creates the directory and returns to an interactive shell when FUSE is ready. Scripts can use `--background` for the same behavior or `--foreground` to supervise the process. Use `adoor mounts` for pending delete confirmations and `adoor unmount ./assets` to disconnect. Background worker logs are in `$XDG_STATE_HOME/adoor/mounts/workers`.
|
|
51
51
|
|
|
52
|
-
MIT licensed.
|
|
52
|
+
The CLI and Swift SDK are MIT licensed. The optional macOS background service is AGPL-3.0-only; its license and corresponding buildable source are included under `native/`.
|
package/dist/adoor.mjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { resolve as resolve6 } from "node:path";
|
|
5
5
|
import { realpath as realpath3 } from "node:fs/promises";
|
|
6
|
-
import { fileURLToPath as
|
|
6
|
+
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
7
7
|
|
|
8
8
|
// src/access.ts
|
|
9
|
-
import { randomUUID as
|
|
9
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
10
10
|
|
|
11
11
|
// src/errors.ts
|
|
12
12
|
var CliError = class extends Error {
|
|
@@ -242,7 +242,7 @@ var DATABASE_TTL = { min: 1, max: 365 * 86400 };
|
|
|
242
242
|
import { open } from "node:fs/promises";
|
|
243
243
|
|
|
244
244
|
// src/version.ts
|
|
245
|
-
var CLI_VERSION = "0.1.
|
|
245
|
+
var CLI_VERSION = "0.1.1";
|
|
246
246
|
|
|
247
247
|
// src/http.ts
|
|
248
248
|
var ACCESS_FILE = "Cloudflare Access requires a private STORE_ACCESS_TOKEN_FILE containing this HTTPS origin and its user token.";
|
|
@@ -683,23 +683,25 @@ function localDatabaseUrl(slug, token, show) {
|
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
// src/db.ts
|
|
686
|
-
import { randomUUID as
|
|
686
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
687
687
|
|
|
688
688
|
// src/config.ts
|
|
689
|
-
import { randomUUID as
|
|
689
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
690
690
|
import { constants as constants2 } from "node:fs";
|
|
691
|
-
import { chmod, mkdir, open as open3, rename, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
691
|
+
import { chmod, mkdir as mkdir2, open as open3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
692
692
|
import { homedir as homedir2 } from "node:os";
|
|
693
693
|
import { dirname as dirname3, join as join3, resolve } from "node:path";
|
|
694
694
|
|
|
695
695
|
// src/desktop.ts
|
|
696
696
|
import { spawn } from "node:child_process";
|
|
697
|
-
import { lstat } from "node:fs/promises";
|
|
697
|
+
import { cp, lstat, mkdir, rename } from "node:fs/promises";
|
|
698
698
|
import { createConnection } from "node:net";
|
|
699
699
|
import { homedir } from "node:os";
|
|
700
700
|
import { dirname, join } from "node:path";
|
|
701
|
-
|
|
702
|
-
|
|
701
|
+
import { fileURLToPath } from "node:url";
|
|
702
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
703
|
+
var installedService = "/Applications/ADoor.app/Contents/Library/ADoorService.app";
|
|
704
|
+
var unavailable = () => new CliError("The ADoor background service is unavailable. Unlock this Mac and retry.", "DESKTOP_UNAVAILABLE");
|
|
703
705
|
var DesktopSession = class {
|
|
704
706
|
constructor(path) {
|
|
705
707
|
this.path = path;
|
|
@@ -746,25 +748,44 @@ async function desktopSession(env) {
|
|
|
746
748
|
if (env.ADOOR_DESKTOP_SESSION === "0" || env.STORE_CONFIG && env.ADOOR_DESKTOP_SESSION !== "1" && !env.ADOOR_SESSION_SOCKET) return;
|
|
747
749
|
if (env.ADOOR_SESSION_SOCKET) return new DesktopSession(env.ADOOR_SESSION_SOCKET);
|
|
748
750
|
if (process.platform !== "darwin") return;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
751
|
+
const root = join(homedir(), "Library", "Application Support", "ADoor");
|
|
752
|
+
const session = new DesktopSession(join(root, "session.sock"));
|
|
753
|
+
try {
|
|
754
|
+
await session.request("config.read");
|
|
755
|
+
return session;
|
|
756
|
+
} catch (error) {
|
|
757
|
+
if (!(error instanceof CliError) || error.code !== "DESKTOP_UNAVAILABLE") throw error;
|
|
758
|
+
}
|
|
759
|
+
const bundled = fileURLToPath(new URL("../native/darwin/ADoorService.app", import.meta.url));
|
|
760
|
+
const stored = join(root, "Service", "ADoorService.app");
|
|
761
|
+
let bundle = await lstat(stored).catch(() => void 0) ? stored : void 0;
|
|
762
|
+
if (!bundle && await lstat(bundled).catch(() => void 0)) {
|
|
763
|
+
await mkdir(root, { recursive: true, mode: 448 });
|
|
764
|
+
const parent = await lstat(root);
|
|
765
|
+
if (!parent.isDirectory() || parent.uid !== process.getuid?.() || (parent.mode & 63) !== 0) {
|
|
766
|
+
throw new CliError("The ADoor service directory must be private and owned by this user.", "DESKTOP_PERMISSIONS");
|
|
767
|
+
}
|
|
768
|
+
const target = join(root, "Service");
|
|
769
|
+
const temp = join(root, `service-${randomUUID2()}`);
|
|
770
|
+
await mkdir(temp, { mode: 448 });
|
|
771
|
+
await cp(bundled, join(temp, "ADoorService.app"), { recursive: true, force: false, errorOnExist: true });
|
|
772
|
+
try {
|
|
773
|
+
await rename(temp, target);
|
|
774
|
+
} catch (error) {
|
|
775
|
+
if (!await lstat(stored).catch(() => void 0)) throw error;
|
|
776
|
+
}
|
|
777
|
+
bundle = stored;
|
|
778
|
+
}
|
|
779
|
+
if (!bundle && await lstat(installedService).catch(() => void 0)) bundle = installedService;
|
|
780
|
+
if (!bundle) return;
|
|
781
|
+
const child = spawn(join(bundle, "Contents", "MacOS", "ADoorService"), [], { env, stdio: "ignore", detached: true });
|
|
782
|
+
let failed = false;
|
|
783
|
+
child.on("error", () => {
|
|
784
|
+
failed = true;
|
|
765
785
|
});
|
|
766
|
-
|
|
786
|
+
child.unref();
|
|
767
787
|
for (let attempt = 0; attempt < 50; attempt++) {
|
|
788
|
+
if (failed) throw unavailable();
|
|
768
789
|
try {
|
|
769
790
|
await session.request("config.read");
|
|
770
791
|
return session;
|
|
@@ -777,7 +798,7 @@ async function desktopSession(env) {
|
|
|
777
798
|
}
|
|
778
799
|
|
|
779
800
|
// src/lock.ts
|
|
780
|
-
import { randomUUID as
|
|
801
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
781
802
|
import { constants, promises as fs } from "node:fs";
|
|
782
803
|
import { open as open2, readdir, unlink, writeFile } from "node:fs/promises";
|
|
783
804
|
import { hostname } from "node:os";
|
|
@@ -795,8 +816,8 @@ function alive(pid) {
|
|
|
795
816
|
}
|
|
796
817
|
var NO_LINKS = /* @__PURE__ */ new Set(["EPERM", "ENOTSUP", "EOPNOTSUPP", "ENOSYS"]);
|
|
797
818
|
async function tryLock(path) {
|
|
798
|
-
const text4 = `${process.pid} ${hostname()} ${
|
|
799
|
-
const temp = `${path}.${
|
|
819
|
+
const text4 = `${process.pid} ${hostname()} ${randomUUID3()}`;
|
|
820
|
+
const temp = `${path}.${randomUUID3()}.tmp`;
|
|
800
821
|
await writeFile(temp, text4, { mode: 384, flag: "wx" });
|
|
801
822
|
try {
|
|
802
823
|
await fs.link(temp, path);
|
|
@@ -869,7 +890,7 @@ async function breakAbandoned(path) {
|
|
|
869
890
|
const found = await readLock(path);
|
|
870
891
|
if (!found) return true;
|
|
871
892
|
if (!abandoned(found)) return false;
|
|
872
|
-
const aside = `${path}.${
|
|
893
|
+
const aside = `${path}.${randomUUID3()}.stale`;
|
|
873
894
|
try {
|
|
874
895
|
await fs.rename(path, aside);
|
|
875
896
|
} catch (error) {
|
|
@@ -1101,10 +1122,10 @@ async function updateConfig(loaded, change) {
|
|
|
1101
1122
|
}
|
|
1102
1123
|
throw new CliError("The shared connections changed. Retry this command.", "CONFIG_CONFLICT");
|
|
1103
1124
|
}
|
|
1104
|
-
await
|
|
1125
|
+
await mkdir2(dirname3(loaded.path), { recursive: true, mode: 448 });
|
|
1105
1126
|
for (; ; ) {
|
|
1106
1127
|
const held = await acquire(loaded.path);
|
|
1107
|
-
const temp = `${loaded.path}.${
|
|
1128
|
+
const temp = `${loaded.path}.${randomUUID4()}.tmp`;
|
|
1108
1129
|
try {
|
|
1109
1130
|
const config = await readConfig(loaded.path);
|
|
1110
1131
|
const swept = decideProfile(config, { type: "sweep", now: Date.now() });
|
|
@@ -1113,7 +1134,7 @@ async function updateConfig(loaded, change) {
|
|
|
1113
1134
|
await writeFile2(temp, JSON.stringify(config, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
1114
1135
|
await chmod(temp, 384);
|
|
1115
1136
|
if (!await holds(held)) continue;
|
|
1116
|
-
await
|
|
1137
|
+
await rename2(temp, loaded.path);
|
|
1117
1138
|
loaded.config = config;
|
|
1118
1139
|
return;
|
|
1119
1140
|
} finally {
|
|
@@ -1284,7 +1305,7 @@ async function dbUrl(app, loaded, input) {
|
|
|
1284
1305
|
const { client } = await clientFor(app, loaded, input.profile);
|
|
1285
1306
|
const workspace = matchWorkspace(await listWorkspaces(client), input.name);
|
|
1286
1307
|
const minted = await mintConnection(client, {
|
|
1287
|
-
name: `url-${
|
|
1308
|
+
name: `url-${randomUUID5().slice(0, 8)}`,
|
|
1288
1309
|
role: "sandbox",
|
|
1289
1310
|
permissions: [{ table: "*", actions: input.readOnly ? ["select"] : [...ROW] }],
|
|
1290
1311
|
expiresIn: ttl,
|
|
@@ -1559,7 +1580,7 @@ async function envCommand(app, loaded, input) {
|
|
|
1559
1580
|
const workspace = matchWorkspace(await listWorkspaces(client), input.database);
|
|
1560
1581
|
const permissions = input.scopes.length ? await compileScopes(client, input.scopes, input.readOnly) : [{ table: "*", actions: input.readOnly ? ["select"] : [...ROW2] }];
|
|
1561
1582
|
const minted = await mintConnection(client, {
|
|
1562
|
-
name: `env-${
|
|
1583
|
+
name: `env-${randomUUID6().slice(0, 8)}`,
|
|
1563
1584
|
role: "sandbox",
|
|
1564
1585
|
permissions,
|
|
1565
1586
|
expiresIn: ttl,
|
|
@@ -1609,7 +1630,7 @@ DATABASE_URL=${fields.DATABASE_URL}
|
|
|
1609
1630
|
|
|
1610
1631
|
// src/machine-grant.ts
|
|
1611
1632
|
import { spawn as spawn2 } from "node:child_process";
|
|
1612
|
-
import { randomUUID as
|
|
1633
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
1613
1634
|
var READ = ["select"];
|
|
1614
1635
|
var WRITE = ["select", "insert", "update", "delete"];
|
|
1615
1636
|
var TABLE2 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
@@ -1745,7 +1766,7 @@ async function grantMachine(app, loaded, input) {
|
|
|
1745
1766
|
...input.allTables ? { allTables: true } : {}
|
|
1746
1767
|
});
|
|
1747
1768
|
const request = {
|
|
1748
|
-
name: `grant-${
|
|
1769
|
+
name: `grant-${randomUUID7().replaceAll("-", "").slice(0, 8)}`,
|
|
1749
1770
|
role: "sandbox",
|
|
1750
1771
|
permissions,
|
|
1751
1772
|
expiresIn: ttl,
|
|
@@ -2699,7 +2720,7 @@ function dev() {
|
|
|
2699
2720
|
}
|
|
2700
2721
|
|
|
2701
2722
|
// src/data.ts
|
|
2702
|
-
import { createHash, randomUUID as
|
|
2723
|
+
import { createHash, randomUUID as randomUUID8 } from "node:crypto";
|
|
2703
2724
|
import { readFile, readdir as readdir2, stat } from "node:fs/promises";
|
|
2704
2725
|
import { basename as basename2, extname, join as join4, resolve as resolve2 } from "node:path";
|
|
2705
2726
|
var TABLE3 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
@@ -2730,7 +2751,7 @@ function writesRows(sql) {
|
|
|
2730
2751
|
return /\binsert\b/i.test(stripped);
|
|
2731
2752
|
}
|
|
2732
2753
|
function commandKey(explicit) {
|
|
2733
|
-
return explicit ??
|
|
2754
|
+
return explicit ?? randomUUID8();
|
|
2734
2755
|
}
|
|
2735
2756
|
function derivedKey(command, label) {
|
|
2736
2757
|
return createHash("sha256").update(`${command}${label}`).digest("hex");
|
|
@@ -2894,7 +2915,7 @@ async function pull(app, loaded, input) {
|
|
|
2894
2915
|
|
|
2895
2916
|
// src/sync/command.ts
|
|
2896
2917
|
import { createHash as createHash3 } from "node:crypto";
|
|
2897
|
-
import { lstat as lstat2, mkdir as
|
|
2918
|
+
import { lstat as lstat2, mkdir as mkdir3, readFile as readFile3, readdir as readdir3, rename as rename3, rm, writeFile as writeFile3 } from "node:fs/promises";
|
|
2898
2919
|
import { basename as basename3, join as join5, resolve as resolve3 } from "node:path";
|
|
2899
2920
|
|
|
2900
2921
|
// src/sync/ignore.ts
|
|
@@ -3232,10 +3253,10 @@ async function pushTree(client, place, local) {
|
|
|
3232
3253
|
return summary;
|
|
3233
3254
|
}
|
|
3234
3255
|
async function writeBytes(dest, bytes) {
|
|
3235
|
-
await
|
|
3256
|
+
await mkdir3(join5(dest, ".."), { recursive: true });
|
|
3236
3257
|
const partial = `${dest}.adoor-partial`;
|
|
3237
3258
|
await writeFile3(partial, bytes);
|
|
3238
|
-
await
|
|
3259
|
+
await rename3(partial, dest);
|
|
3239
3260
|
await rm(`${dest}.adoor-partial.json`, { force: true });
|
|
3240
3261
|
}
|
|
3241
3262
|
async function pullExternal(client, place, node, dest) {
|
|
@@ -3250,7 +3271,7 @@ async function pullExternal(client, place, node, dest) {
|
|
|
3250
3271
|
if (error.code !== "ENOENT") throw error;
|
|
3251
3272
|
}
|
|
3252
3273
|
if (offset === 0) await rm(partial, { force: true });
|
|
3253
|
-
await
|
|
3274
|
+
await mkdir3(join5(dest, ".."), { recursive: true });
|
|
3254
3275
|
while (offset < node.size) {
|
|
3255
3276
|
const length = Math.min(RANGE_BYTES, node.size - offset);
|
|
3256
3277
|
const row = await client.operation("fs.range", callBody(place, { inodeId: node.id, offset, length }));
|
|
@@ -3262,7 +3283,7 @@ async function pullExternal(client, place, node, dest) {
|
|
|
3262
3283
|
offset += chunk.byteLength;
|
|
3263
3284
|
await writeFile3(marker, JSON.stringify({ contentId: node.contentId, generation: node.generation, offset }));
|
|
3264
3285
|
}
|
|
3265
|
-
await
|
|
3286
|
+
await rename3(partial, dest);
|
|
3266
3287
|
await rm(marker, { force: true });
|
|
3267
3288
|
}
|
|
3268
3289
|
async function pullFile(client, place, node, dest, summary) {
|
|
@@ -3290,11 +3311,11 @@ async function pullTree(client, place, local) {
|
|
|
3290
3311
|
const root = await stat2(client, place, place.path);
|
|
3291
3312
|
if (!root) throw new CliError("That remote path was not found.", "NOT_FOUND");
|
|
3292
3313
|
if (root.kind === "file") {
|
|
3293
|
-
await
|
|
3314
|
+
await mkdir3(local, { recursive: true });
|
|
3294
3315
|
await pullFile(client, place, root, join5(local, root.name || basename3(place.path)), summary);
|
|
3295
3316
|
return summary;
|
|
3296
3317
|
}
|
|
3297
|
-
await
|
|
3318
|
+
await mkdir3(local, { recursive: true });
|
|
3298
3319
|
await pullDir(client, place, place.path, local, summary);
|
|
3299
3320
|
return summary;
|
|
3300
3321
|
}
|
|
@@ -3309,7 +3330,7 @@ async function pullDir(client, place, path, local, summary) {
|
|
|
3309
3330
|
const child = joinRemote(path, name);
|
|
3310
3331
|
if (kind === "dir") {
|
|
3311
3332
|
const dir = join5(local, name);
|
|
3312
|
-
await
|
|
3333
|
+
await mkdir3(dir, { recursive: true });
|
|
3313
3334
|
await pullDir(client, place, child, dir, summary);
|
|
3314
3335
|
} else {
|
|
3315
3336
|
const node = await stat2(client, place, child);
|
|
@@ -3425,7 +3446,7 @@ A directory of more than 32 names is not deleted until adoor mount --approve COD
|
|
|
3425
3446
|
import { spawn as spawn6 } from "node:child_process";
|
|
3426
3447
|
import { existsSync } from "node:fs";
|
|
3427
3448
|
import { dirname as dirname4, join as join6 } from "node:path";
|
|
3428
|
-
import { fileURLToPath } from "node:url";
|
|
3449
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3429
3450
|
var LEGACY = /* @__PURE__ */ new Set([
|
|
3430
3451
|
"up",
|
|
3431
3452
|
"connect",
|
|
@@ -3471,7 +3492,7 @@ function refuseIrreversible(positionals) {
|
|
|
3471
3492
|
}
|
|
3472
3493
|
function moduleDirectory() {
|
|
3473
3494
|
try {
|
|
3474
|
-
return dirname4(
|
|
3495
|
+
return dirname4(fileURLToPath2(import.meta.url));
|
|
3475
3496
|
} catch (error) {
|
|
3476
3497
|
if (error instanceof Error) return void 0;
|
|
3477
3498
|
throw error;
|
|
@@ -3527,7 +3548,7 @@ async function delegate(app, argv) {
|
|
|
3527
3548
|
// src/mount/background.ts
|
|
3528
3549
|
import { spawn as spawn7 } from "node:child_process";
|
|
3529
3550
|
import { createHash as createHash4 } from "node:crypto";
|
|
3530
|
-
import { mkdir as
|
|
3551
|
+
import { mkdir as mkdir4, open as open4 } from "node:fs/promises";
|
|
3531
3552
|
import { join as join7, resolve as resolve4 } from "node:path";
|
|
3532
3553
|
var lostParent = () => {
|
|
3533
3554
|
process.kill(process.pid, "SIGTERM");
|
|
@@ -3544,7 +3565,7 @@ function announceMount(app, message) {
|
|
|
3544
3565
|
}
|
|
3545
3566
|
async function backgroundMount(app, entry2, argv, directory, state) {
|
|
3546
3567
|
const folder = join7(state, "workers");
|
|
3547
|
-
await
|
|
3568
|
+
await mkdir4(folder, { recursive: true, mode: 448 });
|
|
3548
3569
|
const name = createHash4("sha256").update(resolve4(directory)).digest("hex");
|
|
3549
3570
|
const log = join7(folder, name + ".log");
|
|
3550
3571
|
const output = await open4(log, "a", 384);
|
|
@@ -3585,8 +3606,8 @@ async function backgroundMount(app, entry2, argv, directory, state) {
|
|
|
3585
3606
|
|
|
3586
3607
|
// src/mount/command.ts
|
|
3587
3608
|
import { spawn as spawn11 } from "node:child_process";
|
|
3588
|
-
import { createHash as createHash11, randomUUID as
|
|
3589
|
-
import { mkdir as
|
|
3609
|
+
import { createHash as createHash11, randomUUID as randomUUID10 } from "node:crypto";
|
|
3610
|
+
import { mkdir as mkdir9, readdir as readdir5, readFile as readFile8, realpath as realpath2, rename as rename7, rm as rm5, stat as stat3, writeFile as writeFile9 } from "node:fs/promises";
|
|
3590
3611
|
import { homedir as homedir4 } from "node:os";
|
|
3591
3612
|
import { basename as basename5, dirname as dirname6, join as join13 } from "node:path";
|
|
3592
3613
|
|
|
@@ -3619,7 +3640,7 @@ function cloudStoragePath(home, workspace, space, scope) {
|
|
|
3619
3640
|
|
|
3620
3641
|
// src/mount/cache.ts
|
|
3621
3642
|
import { createHash as createHash5 } from "node:crypto";
|
|
3622
|
-
import { mkdir as
|
|
3643
|
+
import { mkdir as mkdir5, open as open5, readFile as readFile4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
3623
3644
|
import { join as join8 } from "node:path";
|
|
3624
3645
|
var BlockCache = class {
|
|
3625
3646
|
constructor(dir, cap, now = Date.now) {
|
|
@@ -3648,7 +3669,7 @@ var BlockCache = class {
|
|
|
3648
3669
|
if (bytes.byteLength > this.cap || bytes.byteLength === 0) return;
|
|
3649
3670
|
await this.exclusive(async () => {
|
|
3650
3671
|
await this.load();
|
|
3651
|
-
await
|
|
3672
|
+
await mkdir5(join8(this.dir, "blocks"), { recursive: true });
|
|
3652
3673
|
const dest = join8(this.dir, "blocks", hash);
|
|
3653
3674
|
const temp = `${dest}.tmp`;
|
|
3654
3675
|
const handle = await open5(temp, "w", 384);
|
|
@@ -3663,7 +3684,7 @@ var BlockCache = class {
|
|
|
3663
3684
|
} finally {
|
|
3664
3685
|
await handle.close();
|
|
3665
3686
|
}
|
|
3666
|
-
await
|
|
3687
|
+
await rename4(temp, dest);
|
|
3667
3688
|
this.index.set(hash, { bytes: bytes.byteLength, used: this.now() });
|
|
3668
3689
|
await this.evict();
|
|
3669
3690
|
await this.store();
|
|
@@ -3693,11 +3714,11 @@ var BlockCache = class {
|
|
|
3693
3714
|
}
|
|
3694
3715
|
}
|
|
3695
3716
|
async store() {
|
|
3696
|
-
await
|
|
3717
|
+
await mkdir5(this.dir, { recursive: true });
|
|
3697
3718
|
const dest = join8(this.dir, "index.json");
|
|
3698
3719
|
const temp = `${dest}.tmp`;
|
|
3699
3720
|
await writeFile4(temp, JSON.stringify(Object.fromEntries(this.index)), { mode: 384 });
|
|
3700
|
-
await
|
|
3721
|
+
await rename4(temp, dest);
|
|
3701
3722
|
}
|
|
3702
3723
|
exclusive(work) {
|
|
3703
3724
|
const run2 = this.chain.then(work, work);
|
|
@@ -3775,7 +3796,7 @@ import { createHash as createHash6 } from "node:crypto";
|
|
|
3775
3796
|
import { spawn as spawn9 } from "node:child_process";
|
|
3776
3797
|
import { once as once2 } from "node:events";
|
|
3777
3798
|
import { constants as constants3 } from "node:fs";
|
|
3778
|
-
import { access, mkdir as
|
|
3799
|
+
import { access, mkdir as mkdir6, writeFile as writeFile5 } from "node:fs/promises";
|
|
3779
3800
|
import { homedir as homedir3 } from "node:os";
|
|
3780
3801
|
import { join as join9 } from "node:path";
|
|
3781
3802
|
|
|
@@ -4215,7 +4236,7 @@ async function bridgeBinary(env = process.env) {
|
|
|
4215
4236
|
} catch (error) {
|
|
4216
4237
|
if (error.code !== "ENOENT") throw error;
|
|
4217
4238
|
}
|
|
4218
|
-
await
|
|
4239
|
+
await mkdir6(dir, { recursive: true });
|
|
4219
4240
|
const source = join9(dir, `fuse-bridge-${hash}.c`);
|
|
4220
4241
|
await writeFile5(source, BRIDGE_SOURCE);
|
|
4221
4242
|
await new Promise((resolve7, reject2) => {
|
|
@@ -4571,7 +4592,7 @@ var HttpFiles = class _HttpFiles {
|
|
|
4571
4592
|
|
|
4572
4593
|
// src/mount/journal.ts
|
|
4573
4594
|
import { createHash as createHash9 } from "node:crypto";
|
|
4574
|
-
import { mkdir as
|
|
4595
|
+
import { mkdir as mkdir7, open as open6, readFile as readFile5, rename as rename5, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
|
|
4575
4596
|
import { join as join10 } from "node:path";
|
|
4576
4597
|
function blobName(path) {
|
|
4577
4598
|
return createHash9("sha256").update(path).digest("hex");
|
|
@@ -4640,7 +4661,7 @@ var Journal = class {
|
|
|
4640
4661
|
}
|
|
4641
4662
|
async writeBlob(path, bytes) {
|
|
4642
4663
|
const folder = join10(this.dir, "blobs");
|
|
4643
|
-
await
|
|
4664
|
+
await mkdir7(folder, { recursive: true, mode: 448 });
|
|
4644
4665
|
const dest = join10(folder, blobName(path));
|
|
4645
4666
|
const temp = `${dest}.tmp`;
|
|
4646
4667
|
const handle = await open6(temp, "w", 384);
|
|
@@ -4655,7 +4676,7 @@ var Journal = class {
|
|
|
4655
4676
|
} finally {
|
|
4656
4677
|
await handle.close();
|
|
4657
4678
|
}
|
|
4658
|
-
await
|
|
4679
|
+
await rename5(temp, dest);
|
|
4659
4680
|
}
|
|
4660
4681
|
async load() {
|
|
4661
4682
|
if (this.loaded) return;
|
|
@@ -4671,11 +4692,11 @@ var Journal = class {
|
|
|
4671
4692
|
}
|
|
4672
4693
|
}
|
|
4673
4694
|
async flush() {
|
|
4674
|
-
await
|
|
4695
|
+
await mkdir7(this.dir, { recursive: true, mode: 448 });
|
|
4675
4696
|
const dest = join10(this.dir, "meta.json");
|
|
4676
4697
|
const temp = `${dest}.tmp`;
|
|
4677
4698
|
await writeFile6(temp, JSON.stringify(this.meta), { mode: 384 });
|
|
4678
|
-
await
|
|
4699
|
+
await rename5(temp, dest);
|
|
4679
4700
|
}
|
|
4680
4701
|
};
|
|
4681
4702
|
|
|
@@ -5530,8 +5551,8 @@ var MountOps = class {
|
|
|
5530
5551
|
};
|
|
5531
5552
|
|
|
5532
5553
|
// src/mount/project-link.ts
|
|
5533
|
-
import { createHash as createHash10, randomUUID as
|
|
5534
|
-
import { lstat as lstat3, mkdir as
|
|
5554
|
+
import { createHash as createHash10, randomUUID as randomUUID9 } from "node:crypto";
|
|
5555
|
+
import { lstat as lstat3, mkdir as mkdir8, readFile as readFile7, readdir as readdir4, readlink, realpath, rename as rename6, rm as rm4, symlink, unlink as unlink3, writeFile as writeFile8 } from "node:fs/promises";
|
|
5535
5556
|
import { basename as basename4, dirname as dirname5, join as join12, resolve as resolve5, sep } from "node:path";
|
|
5536
5557
|
var missing = (error) => error.code === "ENOENT";
|
|
5537
5558
|
function occupied(path) {
|
|
@@ -5539,7 +5560,7 @@ function occupied(path) {
|
|
|
5539
5560
|
}
|
|
5540
5561
|
async function projectDestination(arg, knownRoot) {
|
|
5541
5562
|
const path = resolve5(arg);
|
|
5542
|
-
await
|
|
5563
|
+
await mkdir8(dirname5(path), { recursive: true });
|
|
5543
5564
|
const parent = await realpath(dirname5(path));
|
|
5544
5565
|
const destination = join12(parent, basename4(path));
|
|
5545
5566
|
if (knownRoot && destination.startsWith(knownRoot + sep)) throw occupied(destination);
|
|
@@ -5556,7 +5577,7 @@ async function linkProject(destination, target, mountState) {
|
|
|
5556
5577
|
if (destination === target) return;
|
|
5557
5578
|
if (destination.startsWith(target + sep)) throw occupied(destination);
|
|
5558
5579
|
const folder = join12(mountState, "links");
|
|
5559
|
-
await
|
|
5580
|
+
await mkdir8(folder, { recursive: true, mode: 448 });
|
|
5560
5581
|
try {
|
|
5561
5582
|
await symlink(target, destination);
|
|
5562
5583
|
} catch (error) {
|
|
@@ -5566,10 +5587,10 @@ async function linkProject(destination, target, mountState) {
|
|
|
5566
5587
|
}
|
|
5567
5588
|
const info = await lstat3(destination);
|
|
5568
5589
|
const file = linkRecord(folder, destination);
|
|
5569
|
-
const temp = join12(folder, "." +
|
|
5590
|
+
const temp = join12(folder, "." + randomUUID9());
|
|
5570
5591
|
try {
|
|
5571
5592
|
await writeFile8(temp, JSON.stringify({ path: destination, ino: info.ino, dev: info.dev }), { mode: 384 });
|
|
5572
|
-
await
|
|
5593
|
+
await rename6(temp, file);
|
|
5573
5594
|
} catch (error) {
|
|
5574
5595
|
await removeMatchingLink({ path: destination, ino: info.ino, dev: info.dev }, target);
|
|
5575
5596
|
throw error;
|
|
@@ -5854,7 +5875,7 @@ async function mountCommand(app, loaded, spec, hooks = {}) {
|
|
|
5854
5875
|
void preparing?.catch(() => void 0);
|
|
5855
5876
|
if (!spec.resume) {
|
|
5856
5877
|
try {
|
|
5857
|
-
await
|
|
5878
|
+
await mkdir9(destination, { recursive: true });
|
|
5858
5879
|
} catch (error) {
|
|
5859
5880
|
if (["EEXIST", "ENOTDIR"].includes(error.code ?? "")) {
|
|
5860
5881
|
throw new CliError(`Choose a directory for the mount. ${destination} is occupied.`, "INVALID_ARGUMENT");
|
|
@@ -5867,7 +5888,7 @@ async function mountCommand(app, loaded, spec, hooks = {}) {
|
|
|
5867
5888
|
if (await fuseMounted(directory)) throw new CliError(`${directory} is already mounted.`, "MOUNT_UNAVAILABLE");
|
|
5868
5889
|
if ((await readdir5(directory)).length) throw new CliError(`Choose an empty mount directory. ${directory} contains files.`, "INVALID_ARGUMENT");
|
|
5869
5890
|
const folder = join13(stateRoot(app.env), mountId(directory));
|
|
5870
|
-
await
|
|
5891
|
+
await mkdir9(folder, { recursive: true, mode: 448 });
|
|
5871
5892
|
const found = await keyring;
|
|
5872
5893
|
const token = found || saved.token;
|
|
5873
5894
|
remember(token);
|
|
@@ -6165,7 +6186,7 @@ async function publishFileProvider(app, loaded, spec, hooks) {
|
|
|
6165
6186
|
await storeCredential(app, link.token, link.origin, id);
|
|
6166
6187
|
record.dir = await manageProvider(app.env, "--register-domain", id, record.space);
|
|
6167
6188
|
const folder = join13(stateRoot(app.env), mountId(record.dir));
|
|
6168
|
-
await
|
|
6189
|
+
await mkdir9(folder, { recursive: true, mode: 448 });
|
|
6169
6190
|
await writeFile9(join13(folder, "mount.json"), JSON.stringify(record), { mode: 384 });
|
|
6170
6191
|
await writeSharedBook(app.env, sharedEntry(record, link.origin, "mounted"));
|
|
6171
6192
|
if (located && located.folder !== folder) await rm5(join13(located.folder, "mount.json"), { force: true });
|
|
@@ -6218,7 +6239,7 @@ async function readSharedBook(path) {
|
|
|
6218
6239
|
}
|
|
6219
6240
|
async function writeSharedBook(env, entry2) {
|
|
6220
6241
|
const path = registryPath(env);
|
|
6221
|
-
await
|
|
6242
|
+
await mkdir9(dirname6(path), { recursive: true, mode: 448 });
|
|
6222
6243
|
let mounts = await readSharedBook(path);
|
|
6223
6244
|
const matches3 = (item) => item.id === entry2.id || item.localPath === entry2.localPath;
|
|
6224
6245
|
const previous = mounts.find(matches3);
|
|
@@ -6226,10 +6247,10 @@ async function writeSharedBook(env, entry2) {
|
|
|
6226
6247
|
if (!entry2.server && previous?.server) entry2.server = previous.server;
|
|
6227
6248
|
mounts = mounts.filter((item) => !matches3(item));
|
|
6228
6249
|
mounts.push(entry2);
|
|
6229
|
-
const temp = `${path}.${
|
|
6250
|
+
const temp = `${path}.${randomUUID10()}.tmp`;
|
|
6230
6251
|
try {
|
|
6231
6252
|
await writeFile9(temp, JSON.stringify({ version: 1, mounts }), { mode: 384 });
|
|
6232
|
-
await
|
|
6253
|
+
await rename7(temp, path);
|
|
6233
6254
|
} finally {
|
|
6234
6255
|
await rm5(temp, { force: true });
|
|
6235
6256
|
}
|
|
@@ -6240,10 +6261,10 @@ async function storeCredential(app, token, origin, domain) {
|
|
|
6240
6261
|
await handToken(binary, origin, token, domain, app.env);
|
|
6241
6262
|
}
|
|
6242
6263
|
async function manageProvider(env, operation, id, label) {
|
|
6243
|
-
const
|
|
6244
|
-
if (!
|
|
6264
|
+
const helper = keychainHelper(env);
|
|
6265
|
+
if (!helper) throw new CliError("Install ADoor for Mac in Applications to mount a Finder folder.", "MOUNT_UNAVAILABLE");
|
|
6245
6266
|
return new Promise((resolve7, reject2) => {
|
|
6246
|
-
const child = spawn11(
|
|
6267
|
+
const child = spawn11(helper, [operation, id, label], { stdio: ["ignore", "pipe", "pipe"], env });
|
|
6247
6268
|
let output = "";
|
|
6248
6269
|
let error = "";
|
|
6249
6270
|
child.stdout?.on("data", (chunk) => {
|
|
@@ -6262,10 +6283,10 @@ async function manageProvider(env, operation, id, label) {
|
|
|
6262
6283
|
}
|
|
6263
6284
|
async function openMacApp(env) {
|
|
6264
6285
|
if (env.ADOOR_MOUNT_OPEN === "0" || process.platform !== "darwin") return;
|
|
6265
|
-
const
|
|
6266
|
-
if (!
|
|
6286
|
+
const helper = keychainHelper(env);
|
|
6287
|
+
if (!helper) return;
|
|
6267
6288
|
const status = await new Promise((resolve7) => {
|
|
6268
|
-
const child = spawn11(
|
|
6289
|
+
const child = spawn11(helper, ["--open-if-needed"], { stdio: "ignore", env });
|
|
6269
6290
|
child.on("error", () => resolve7(null));
|
|
6270
6291
|
child.on("close", resolve7);
|
|
6271
6292
|
});
|
|
@@ -6870,7 +6891,7 @@ async function runOnce(argv, options) {
|
|
|
6870
6891
|
if ((foreground || background) && (approve || process.platform !== "linux")) usage("Use these flags for a Linux mount.");
|
|
6871
6892
|
const terminal = app.stdout === process.stdout && process.stdout.isTTY === true;
|
|
6872
6893
|
if (process.platform === "linux" && !approve && !foreground && (background || terminal) && (target || dir)) {
|
|
6873
|
-
await backgroundMount(app,
|
|
6894
|
+
await backgroundMount(app, fileURLToPath3(import.meta.url), argv, dir ?? target ?? "", stateRoot(app.env));
|
|
6874
6895
|
return 0;
|
|
6875
6896
|
}
|
|
6876
6897
|
await mountCommand(app, loaded, {
|