@narumitw/pi-sync 0.67.3 → 0.68.0
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 +7 -0
- package/README.md +26 -48
- package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
- package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
- package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-HLJIRWFL.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-AVTW6WNP.ts → chunk-FQKWGVMA.ts} +20 -54
- package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
- package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
- package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
- package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
- package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
- package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
- package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
- package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
- package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
- package/dist/chunks/{chunk-X344HTVV.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{chunk-CQ4DMLH3.ts → chunk-YV2R5SJU.ts} +21 -81
- package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
- package/dist/chunks/{command-handler-WF2TDDRZ.ts → command-handler-S6BRZMPW.ts} +64 -59
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
- package/dist/chunks/{conflict-review-GWEL4S6C.ts → conflict-review-3XMYDJIK.ts} +2 -2
- package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
- package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-FS4QIKRA.ts → manager-ui-KHMCSLLV.ts} +114 -581
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
- package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
- package/dist/chunks/{remote-selection-ui-DOYKUMER.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
- package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
- package/dist/chunks/{setup-wizard-PI45SF2C.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-PI45SF2C.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-DI5J6EUH.ts → sync-inspection-QGM54YCM.ts} +5 -5
- package/dist/chunks/{sync-operations-AGNL7QXA.ts → sync-operations-DTQMKVRQ.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -1
- package/dist/daemon/dist/cli.js +22 -3
- package/dist/daemon/dist/client-transport.js +2 -0
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -135
- package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
- package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
- package/dist/daemon/dist/engine/settings/config.js +16 -149
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
- package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
- package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
- package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
- package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
- package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
- package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
- package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
- package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
- package/dist/daemon/dist/engine/sync/initialization.js +4 -15
- package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
- package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
- package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
- package/dist/daemon/dist/engine/sync/merged-sync.js +12 -70
- package/dist/daemon/dist/engine/sync/push-review.js +1 -16
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
- package/dist/daemon/dist/engine/sync/sync-mutations.js +25 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
- package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
- package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
- package/dist/daemon/dist/engine-service.js +60 -219
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +4 -8
- package/dist/daemon/dist/service-host.js +3 -9
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +45 -46
- package/dist/index.ts.map +3 -3
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +7 -5
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +18 -77
- package/skills/configure-pi-sync/references/configuration.md +58 -75
- package/src/commands/command-execution.ts +13 -29
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +20 -88
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +10 -24
- package/src/ui/cancellable-operation.ts +2 -13
- package/src/ui/excluded-paths-ui.ts +1 -4
- package/src/ui/file-selection.ts +0 -5
- package/src/ui/manager-state.ts +12 -75
- package/src/ui/manager-ui.ts +7 -96
- package/src/ui/remote-selection-ui.ts +29 -130
- package/src/ui/settings-ui.ts +169 -388
- package/src/ui/setup/setup-actions.ts +4 -16
- package/src/ui/setup/setup-prompts.ts +12 -49
- package/src/ui/setup/setup-switcher.ts +8 -14
- package/src/ui/storage-connections-ui.ts +21 -32
- package/src/ui/sync-setups-ui.ts +27 -53
- package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
- package/dist/chunks/chunk-33EDXDLC.ts +0 -106
- package/dist/chunks/chunk-33EDXDLC.ts.map +0 -7
- package/dist/chunks/chunk-AVTW6WNP.ts.map +0 -7
- package/dist/chunks/chunk-CQ4DMLH3.ts.map +0 -7
- package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
- package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
- package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
- package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
- package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
- package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
- package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/chunk-X344HTVV.ts.map +0 -7
- package/dist/chunks/command-handler-WF2TDDRZ.ts.map +0 -7
- package/dist/chunks/config-P54GGMXY.ts +0 -39
- package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
- package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
- package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
- package/dist/chunks/ignore-file-ui-BEZZZIEE.ts +0 -21
- package/dist/chunks/manager-ui-FS4QIKRA.ts.map +0 -7
- package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
- package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-DOYKUMER.ts.map +0 -7
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
- package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
- package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
- package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
- package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
- package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
- package/dist/daemon/dist/monitor.js +0 -344
- package/src/ui/agent-mode-setting.ts +0 -99
- package/src/ui/ignore-file-guidance.ts +0 -7
- package/src/ui/ignore-file-ui.ts +0 -105
- package/src/ui/ignore-migration-prompt.ts +0 -65
- package/src/ui/settings-review.ts +0 -26
- /package/dist/chunks/{chunk-HLJIRWFL.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
- /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
- /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
- /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-GWEL4S6C.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
- /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-BEZZZIEE.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-DI5J6EUH.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-AGNL7QXA.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { constants, lstatSync } from "node:fs";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { validateConfigName } from "../settings/settings-validation.js";
|
|
6
|
-
import { syncDirectory, writeJson } from "../state/json-file.js";
|
|
7
|
-
import { stateDir } from "../state/state-directory.js";
|
|
8
|
-
import { compileIgnoreRules, sameFile, validateIgnoreFilename } from "./ignore-source.js";
|
|
9
|
-
const MAX_BYTES = 32 * 1024 * 1024;
|
|
10
|
-
const recoveryMessage = "Pending ignore-rule adoption. Run a reviewed Pull from the originating setup, or preserve its recovery evidence.";
|
|
11
|
-
function journalPath() {
|
|
12
|
-
return path.join(stateDir(), "ignore-adoption.json");
|
|
13
|
-
}
|
|
14
|
-
export function hasPendingAdoption() {
|
|
15
|
-
return lstatSync(journalPath(), { throwIfNoEntry: false }) !== undefined;
|
|
16
|
-
}
|
|
17
|
-
export function requireNoPendingAdoption() {
|
|
18
|
-
if (hasPendingAdoption())
|
|
19
|
-
throw new Error(recoveryMessage);
|
|
20
|
-
}
|
|
21
|
-
function hex(value) {
|
|
22
|
-
return typeof value === "string" && /^[a-f0-9]{64}$/u.test(value);
|
|
23
|
-
}
|
|
24
|
-
function fileIdentity(value) {
|
|
25
|
-
return typeof value === "string" && /^\d+:\d+:-?\d+$/u.test(value);
|
|
26
|
-
}
|
|
27
|
-
function hashMap(value) {
|
|
28
|
-
return Boolean(value &&
|
|
29
|
-
typeof value === "object" &&
|
|
30
|
-
!Array.isArray(value) &&
|
|
31
|
-
Object.keys(value).length <= 16_384 &&
|
|
32
|
-
Object.values(value).every(hex));
|
|
33
|
-
}
|
|
34
|
-
async function readAdoptionJournal() {
|
|
35
|
-
const target = journalPath();
|
|
36
|
-
const before = await fs.lstat(target);
|
|
37
|
-
if (!before.isFile() ||
|
|
38
|
-
before.nlink !== 1 ||
|
|
39
|
-
before.size > MAX_BYTES ||
|
|
40
|
-
(process.getuid && before.uid !== process.getuid()) ||
|
|
41
|
-
(process.platform !== "win32" && before.mode & 0o077))
|
|
42
|
-
throw new Error(recoveryMessage);
|
|
43
|
-
const handle = await fs.open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
44
|
-
try {
|
|
45
|
-
const stat = await handle.stat();
|
|
46
|
-
if (stat.dev !== before.dev ||
|
|
47
|
-
stat.ino !== before.ino ||
|
|
48
|
-
stat.size !== before.size ||
|
|
49
|
-
stat.mtimeMs !== before.mtimeMs)
|
|
50
|
-
throw new Error(recoveryMessage);
|
|
51
|
-
const bytes = Buffer.alloc(stat.size);
|
|
52
|
-
const { bytesRead } = await handle.read(bytes);
|
|
53
|
-
if (bytesRead !== bytes.length || (await handle.stat()).mtimeMs !== stat.mtimeMs)
|
|
54
|
-
throw new Error(recoveryMessage);
|
|
55
|
-
return JSON.parse(bytes.toString("utf8"));
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
await handle.close();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export async function loadAdoptionJournal() {
|
|
62
|
-
if (!hasPendingAdoption())
|
|
63
|
-
return;
|
|
64
|
-
try {
|
|
65
|
-
const journal = await readAdoptionJournal();
|
|
66
|
-
if (journal?.version !== 1 ||
|
|
67
|
-
!hex(journal.setupFingerprint) ||
|
|
68
|
-
!hex(journal.stateFingerprint) ||
|
|
69
|
-
!fileIdentity(journal.sourceIdentity) ||
|
|
70
|
-
(journal.installedIdentity !== undefined && !fileIdentity(journal.installedIdentity)) ||
|
|
71
|
-
typeof journal.beforeRules !== "string" ||
|
|
72
|
-
typeof journal.afterRules !== "string" ||
|
|
73
|
-
!hashMap(journal.beforeFiles) ||
|
|
74
|
-
!hashMap(journal.afterFiles) ||
|
|
75
|
-
!hex(journal.remoteFilesIdentity) ||
|
|
76
|
-
!hex(journal.backupDigest) ||
|
|
77
|
-
typeof journal.head?.snapshotId !== "string" ||
|
|
78
|
-
typeof journal.head?.snapshotRef !== "string" ||
|
|
79
|
-
typeof journal.head?.revision !== "string" ||
|
|
80
|
-
(journal.sessionDir !== undefined && !path.isAbsolute(journal.sessionDir)) ||
|
|
81
|
-
typeof journal.backupId !== "string" ||
|
|
82
|
-
!/^[\w-]{1,128}$/u.test(journal.backupId))
|
|
83
|
-
throw new Error(recoveryMessage);
|
|
84
|
-
validateConfigName(journal.setupName, "sync setup");
|
|
85
|
-
validateIgnoreFilename(journal.filename);
|
|
86
|
-
compileIgnoreRules(journal.beforeRules);
|
|
87
|
-
compileIgnoreRules(journal.afterRules);
|
|
88
|
-
return journal;
|
|
89
|
-
}
|
|
90
|
-
catch (cause) {
|
|
91
|
-
throw new Error(recoveryMessage, { cause });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export async function verifyAdoptionBackup(journal, signal) {
|
|
95
|
-
const backups = path.join(stateDir(), "backups");
|
|
96
|
-
if (!(await fs.lstat(backups)).isDirectory())
|
|
97
|
-
throw new Error(recoveryMessage);
|
|
98
|
-
const backup = path.join(backups, `${journal.backupId}.json.gz`);
|
|
99
|
-
const handle = await fs.open(backup, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
100
|
-
try {
|
|
101
|
-
const stat = await handle.stat({ bigint: true });
|
|
102
|
-
if (!stat.isFile() || stat.nlink !== 1n || stat.size < 1n || stat.size > 128n * 1024n * 1024n)
|
|
103
|
-
throw new Error(recoveryMessage);
|
|
104
|
-
const hash = createHash("sha256");
|
|
105
|
-
const stream = handle.createReadStream({ start: 0, end: Number(stat.size) - 1, autoClose: false, signal });
|
|
106
|
-
for await (const chunk of stream)
|
|
107
|
-
hash.update(chunk);
|
|
108
|
-
if (hash.digest("hex") !== journal.backupDigest || !sameFile(stat, await fs.lstat(backup, { bigint: true })))
|
|
109
|
-
throw new Error("The original Pull backup changed; preserve the adoption journal.");
|
|
110
|
-
signal?.throwIfAborted();
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
await handle.close();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export function adoptionJournalFingerprint(journal) {
|
|
117
|
-
return createHash("sha256").update(JSON.stringify(journal)).digest("hex");
|
|
118
|
-
}
|
|
119
|
-
export async function createAdoptionJournal(journal) {
|
|
120
|
-
requireNoPendingAdoption();
|
|
121
|
-
const target = journalPath();
|
|
122
|
-
await writeJson(target, journal, { maxBytes: MAX_BYTES });
|
|
123
|
-
await syncDirectory(path.dirname(path.dirname(target)));
|
|
124
|
-
}
|
|
125
|
-
export async function assertCurrentAdoptionJournal(journal) {
|
|
126
|
-
if (JSON.stringify(await loadAdoptionJournal()) !== JSON.stringify(journal))
|
|
127
|
-
throw new Error(recoveryMessage);
|
|
128
|
-
}
|
|
129
|
-
export async function recordInstalledIdentity(journal, identity) {
|
|
130
|
-
await assertCurrentAdoptionJournal(journal);
|
|
131
|
-
const next = { ...journal, installedIdentity: identity };
|
|
132
|
-
await writeJson(journalPath(), next, { maxBytes: MAX_BYTES });
|
|
133
|
-
return next;
|
|
134
|
-
}
|
|
135
|
-
export async function completeAdoptionJournal(journal) {
|
|
136
|
-
await assertCurrentAdoptionJournal(journal);
|
|
137
|
-
const target = journalPath();
|
|
138
|
-
const backups = path.join(path.dirname(target), "backups");
|
|
139
|
-
if (!(await fs.lstat(backups)).isDirectory())
|
|
140
|
-
throw new Error(recoveryMessage);
|
|
141
|
-
const archived = path.join(backups, `${journal.backupId}.ignore-adoption.json`);
|
|
142
|
-
await fs.rename(target, archived);
|
|
143
|
-
await syncDirectory(backups);
|
|
144
|
-
await syncDirectory(path.dirname(target));
|
|
145
|
-
return archived;
|
|
146
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { compileIgnoreRules, DEFAULT_IGNORE_FILENAME, ignorePolicyFingerprint, readIgnoreSource, validateIgnoreFilename, } from "./ignore-source.js";
|
|
2
|
-
function reservedNames(filename, configuredFilenames) {
|
|
3
|
-
return [
|
|
4
|
-
...new Set([DEFAULT_IGNORE_FILENAME, filename, ...configuredFilenames].map((name) => validateIgnoreFilename(name).toLowerCase())),
|
|
5
|
-
].sort();
|
|
6
|
-
}
|
|
7
|
-
export async function loadEffectiveIgnorePolicy(root, input, signal) {
|
|
8
|
-
const source = await readIgnoreSource(root, input.filename, signal);
|
|
9
|
-
signal?.throwIfAborted();
|
|
10
|
-
return compileEffectiveIgnorePolicy(source, input);
|
|
11
|
-
}
|
|
12
|
-
export function compileEffectiveIgnorePolicy(source, input) {
|
|
13
|
-
return {
|
|
14
|
-
filename: source.filename,
|
|
15
|
-
sourceDigest: source.sourceDigest,
|
|
16
|
-
fingerprint: ignorePolicyFingerprint(source.text, input.sessions),
|
|
17
|
-
sessions: input.sessions,
|
|
18
|
-
reservedNames: reservedNames(source.filename, input.configuredFilenames),
|
|
19
|
-
matches: compileIgnoreRules(source.text),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export async function requireUnchangedIgnorePolicy(root, reviewed, current, signal) {
|
|
23
|
-
const source = await readIgnoreSource(root, current.filename, signal);
|
|
24
|
-
signal?.throwIfAborted();
|
|
25
|
-
const currentNames = reservedNames(source.filename, current.configuredFilenames);
|
|
26
|
-
if (reviewed.filename !== source.filename ||
|
|
27
|
-
reviewed.sourceDigest !== source.sourceDigest ||
|
|
28
|
-
reviewed.sessions !== current.sessions ||
|
|
29
|
-
reviewed.reservedNames.length !== currentNames.length ||
|
|
30
|
-
reviewed.reservedNames.some((name, index) => name !== currentNames[index])) {
|
|
31
|
-
throw new Error("Pi Sync ignore policy changed; reopen the review before continuing.");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { lstatSync, statSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { record } from "../../protocol.js";
|
|
5
|
-
import { getEngineRoot } from "../host.js";
|
|
6
|
-
import { withLockedLocalConfigDocument } from "../settings/config-file.js";
|
|
7
|
-
import { validateConfigName, validateSettingsDocument } from "../settings/settings-validation.js";
|
|
8
|
-
import { compileIgnoreRules, DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILENAME, ignoreFileIdentity, readIgnoreSource, sameFile, } from "./ignore-source.js";
|
|
9
|
-
function locateIgnoreFile(document, root, setup) {
|
|
10
|
-
const settings = document && validateSettingsDocument(document.parsed);
|
|
11
|
-
const current = settings && Object.hasOwn(settings.syncSetups, setup) ? settings.syncSetups[setup] : undefined;
|
|
12
|
-
if (!settings || !current)
|
|
13
|
-
throw new Error("Sync setup no longer exists; reopen ignore-file settings.");
|
|
14
|
-
if (current.sync.pathPolicy !== "ignore-file")
|
|
15
|
-
throw new Error("This sync setup does not use an ignore file.");
|
|
16
|
-
const filename = current.sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME;
|
|
17
|
-
return {
|
|
18
|
-
filename,
|
|
19
|
-
path: path.join(root, filename),
|
|
20
|
-
sharingSetups: Object.entries(settings.syncSetups)
|
|
21
|
-
.filter(([name, { sync }]) => name !== setup &&
|
|
22
|
-
sync.scope === "agent-directory" &&
|
|
23
|
-
sync.pathPolicy === "ignore-file" &&
|
|
24
|
-
(sync.ignoreFile ?? DEFAULT_IGNORE_FILENAME) === filename)
|
|
25
|
-
.map(([name]) => name)
|
|
26
|
-
.sort(),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function statAt(target) {
|
|
30
|
-
return lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
31
|
-
}
|
|
32
|
-
function stale(target) {
|
|
33
|
-
throw new Error(`Ignore file changed or disappeared at "${target}"; reopen ignore-file settings.`);
|
|
34
|
-
}
|
|
35
|
-
function assertCurrent(target, expected) {
|
|
36
|
-
const current = statAt(target);
|
|
37
|
-
if (expected ? !current || !sameFile(expected, current) : current)
|
|
38
|
-
stale(target);
|
|
39
|
-
}
|
|
40
|
-
function validateTarget(execution, location) {
|
|
41
|
-
execution.validate();
|
|
42
|
-
const root = getEngineRoot();
|
|
43
|
-
if (location.filename === DEFAULT_IGNORE_FILENAME && statAt(path.join(root, DEFAULT_IGNORE_CREATION_RECORD))) {
|
|
44
|
-
throw new Error(`Ignore file "${location.path}" has an unfinished creation record; repair it before editing.`);
|
|
45
|
-
}
|
|
46
|
-
const target = statAt(location.path);
|
|
47
|
-
if (target &&
|
|
48
|
-
execution.liveClients().some(({ sessionFile }) => {
|
|
49
|
-
const session = sessionFile && statSync(sessionFile, { bigint: true, throwIfNoEntry: false });
|
|
50
|
-
return session && target.dev === session.dev && target.ino === session.ino;
|
|
51
|
-
}))
|
|
52
|
-
throw new Error(`Ignore file "${location.path}" is a protected live session.`);
|
|
53
|
-
return { root, target };
|
|
54
|
-
}
|
|
55
|
-
function editorDigest(setup, location, sourceDigest) {
|
|
56
|
-
return createHash("sha256")
|
|
57
|
-
.update(JSON.stringify(["pi-sync-ignore-editor-v1", setup, sourceDigest, location.sharingSetups]))
|
|
58
|
-
.digest("hex");
|
|
59
|
-
}
|
|
60
|
-
async function loadEditorSource(setup, location, execution) {
|
|
61
|
-
const { root, target: stat } = validateTarget(execution, location);
|
|
62
|
-
if (!stat)
|
|
63
|
-
return { location };
|
|
64
|
-
try {
|
|
65
|
-
const source = await readIgnoreSource(root, location.filename, execution.signal);
|
|
66
|
-
validateTarget(execution, location);
|
|
67
|
-
assertCurrent(location.path, stat);
|
|
68
|
-
if (!source.present || source.identity !== ignoreFileIdentity(stat))
|
|
69
|
-
stale(location.path);
|
|
70
|
-
compileIgnoreRules(source.text);
|
|
71
|
-
const { text, identity } = source;
|
|
72
|
-
return {
|
|
73
|
-
location,
|
|
74
|
-
existing: {
|
|
75
|
-
view: { ...location, text, sourceDigest: editorDigest(setup, location, source.sourceDigest), identity },
|
|
76
|
-
stat,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
catch (cause) {
|
|
81
|
-
execution.validate();
|
|
82
|
-
throw new Error(`Cannot open ignore file "${location.path}": ${cause.message}`, { cause });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export async function readIgnoreFileEdit(payload, execution) {
|
|
86
|
-
if (!record(payload) || typeof payload.setup !== "string" || Object.keys(payload).some((key) => key !== "setup"))
|
|
87
|
-
throw new Error("Invalid ignore-file request.");
|
|
88
|
-
const { setup } = payload;
|
|
89
|
-
validateConfigName(setup, "sync setup");
|
|
90
|
-
const source = await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
91
|
-
execution.validate();
|
|
92
|
-
const location = locateIgnoreFile(document, getEngineRoot(), setup);
|
|
93
|
-
const result = await loadEditorSource(setup, location, execution);
|
|
94
|
-
validateTarget(execution, location);
|
|
95
|
-
recheck();
|
|
96
|
-
assertCurrent(location.path, result.existing?.stat);
|
|
97
|
-
return result;
|
|
98
|
-
}, execution.signal);
|
|
99
|
-
validateTarget(execution, source.location);
|
|
100
|
-
assertCurrent(source.location.path, source.existing?.stat);
|
|
101
|
-
return source.existing?.view ?? source.location;
|
|
102
|
-
}
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { constants, lstatSync, realpathSync, unlinkSync } from "node:fs";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILENAME, DEFAULT_IGNORE_RULES, ignoreFileIdentity, readIgnoreSource, sameFile, sameIdentity, } from "./ignore-source.js";
|
|
5
|
-
const recordPrefix = "pi-sync-ignore-creation-v1\n";
|
|
6
|
-
const records = [
|
|
7
|
-
Buffer.from(`${recordPrefix}${DEFAULT_IGNORE_RULES}`),
|
|
8
|
-
Buffer.from(`${recordPrefix}/npm/\n/sessions/\n/auth.json\n/truth.json\n`),
|
|
9
|
-
];
|
|
10
|
-
const noFollow = (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
11
|
-
const openRead = constants.O_RDONLY | noFollow;
|
|
12
|
-
const openExisting = process.platform === "win32" ? constants.O_RDWR | noFollow : openRead;
|
|
13
|
-
const openExclusive = constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | noFollow;
|
|
14
|
-
export class AutomaticIgnoreCreationUnavailable extends Error {
|
|
15
|
-
}
|
|
16
|
-
export async function checkAutomaticIgnoreCreation(root, signal) {
|
|
17
|
-
signal.throwIfAborted();
|
|
18
|
-
root = path.resolve(root);
|
|
19
|
-
const expected = await fs.lstat(root, { bigint: true });
|
|
20
|
-
signal.throwIfAborted();
|
|
21
|
-
assertRoot(root, expected);
|
|
22
|
-
await checkCreationAccess(root);
|
|
23
|
-
const { directory } = await openCreationDirectory(root, expected);
|
|
24
|
-
try {
|
|
25
|
-
signal.throwIfAborted();
|
|
26
|
-
await syncCreationDirectory(directory);
|
|
27
|
-
assertRoot(root, expected);
|
|
28
|
-
}
|
|
29
|
-
finally {
|
|
30
|
-
await directory?.close();
|
|
31
|
-
signal.throwIfAborted();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function creationRecordToken(stat) {
|
|
35
|
-
return `${ignoreFileIdentity(stat)}:${stat.size}:${stat.ctimeNs}:${stat.mtimeNs}`;
|
|
36
|
-
}
|
|
37
|
-
export async function readPendingIgnoreCreation(root, signal) {
|
|
38
|
-
signal.throwIfAborted();
|
|
39
|
-
root = path.resolve(root);
|
|
40
|
-
const initialRoot = await fs.lstat(root, { bigint: true });
|
|
41
|
-
const checkRoot = () => {
|
|
42
|
-
signal.throwIfAborted();
|
|
43
|
-
assertRoot(root, initialRoot);
|
|
44
|
-
};
|
|
45
|
-
checkRoot();
|
|
46
|
-
const target = path.join(root, DEFAULT_IGNORE_CREATION_RECORD);
|
|
47
|
-
const prior = await fs.lstat(target, { bigint: true });
|
|
48
|
-
assertOwned(prior, DEFAULT_IGNORE_CREATION_RECORD, true);
|
|
49
|
-
const marker = await fs.open(target, openRead);
|
|
50
|
-
try {
|
|
51
|
-
const { stat, bytes } = await verifyCreationFile(marker, target, target, records, checkRoot, prior, false);
|
|
52
|
-
return { token: creationRecordToken(stat), text: bytes.toString("utf8", recordPrefix.length) };
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
await marker.close();
|
|
56
|
-
signal.throwIfAborted();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export async function initializeDefaultIgnoreSource(root, signal) {
|
|
60
|
-
return (await prepareDefaultIgnoreSource(root, signal)).source;
|
|
61
|
-
}
|
|
62
|
-
export async function prepareDefaultIgnoreSource(root, signal, reviewedCreation) {
|
|
63
|
-
signal?.throwIfAborted();
|
|
64
|
-
root = path.resolve(root);
|
|
65
|
-
try {
|
|
66
|
-
const initialRoot = await fs.lstat(root, { bigint: true });
|
|
67
|
-
const verifyRoot = () => assertRoot(root, initialRoot);
|
|
68
|
-
const checkRoot = () => {
|
|
69
|
-
signal?.throwIfAborted();
|
|
70
|
-
verifyRoot();
|
|
71
|
-
};
|
|
72
|
-
checkRoot();
|
|
73
|
-
const priorRecord = statAt(path.join(root, DEFAULT_IGNORE_CREATION_RECORD));
|
|
74
|
-
if (reviewedCreation !== undefined &&
|
|
75
|
-
reviewedCreation !== (priorRecord ? creationRecordToken(priorRecord) : null)) {
|
|
76
|
-
changed(DEFAULT_IGNORE_CREATION_RECORD);
|
|
77
|
-
}
|
|
78
|
-
if (!priorRecord) {
|
|
79
|
-
const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
|
|
80
|
-
checkRoot();
|
|
81
|
-
if (source.present)
|
|
82
|
-
return { source, created: false };
|
|
83
|
-
}
|
|
84
|
-
await checkCreationAccess(root);
|
|
85
|
-
const { directory, anchor } = await openCreationDirectory(root, initialRoot);
|
|
86
|
-
try {
|
|
87
|
-
checkRoot();
|
|
88
|
-
const flushDirectory = await syncCreationDirectory(directory);
|
|
89
|
-
checkRoot();
|
|
90
|
-
const markerPath = path.join(anchor, DEFAULT_IGNORE_CREATION_RECORD);
|
|
91
|
-
const target = path.join(anchor, DEFAULT_IGNORE_FILENAME);
|
|
92
|
-
if (priorRecord)
|
|
93
|
-
assertOwned(priorRecord, DEFAULT_IGNORE_CREATION_RECORD, true);
|
|
94
|
-
else if (statAt(target))
|
|
95
|
-
changed(DEFAULT_IGNORE_FILENAME);
|
|
96
|
-
const marker = await fs.open(markerPath, priorRecord ? openExisting : openExclusive, 0o600).catch((error) => {
|
|
97
|
-
if (!priorRecord)
|
|
98
|
-
checkCreationError(error);
|
|
99
|
-
throw error;
|
|
100
|
-
});
|
|
101
|
-
try {
|
|
102
|
-
const { stat: markerStat, bytes } = await verifyCreationFile(marker, markerPath, path.join(root, DEFAULT_IGNORE_CREATION_RECORD), records, priorRecord ? checkRoot : verifyRoot, priorRecord);
|
|
103
|
-
const starter = bytes.subarray(recordPrefix.length);
|
|
104
|
-
await flushDirectory();
|
|
105
|
-
checkRoot();
|
|
106
|
-
assertCurrent(markerPath, markerStat);
|
|
107
|
-
const priorFile = priorRecord ? statAt(target) : undefined;
|
|
108
|
-
if (priorFile)
|
|
109
|
-
assertOwned(priorFile, DEFAULT_IGNORE_FILENAME, false);
|
|
110
|
-
const file = await fs.open(target, priorFile ? openExisting : openExclusive, 0o600).catch(async (cause) => {
|
|
111
|
-
if (!priorRecord && cause.code === "EEXIST") {
|
|
112
|
-
verifyRoot();
|
|
113
|
-
assertCurrent(markerPath, markerStat);
|
|
114
|
-
unlinkSync(markerPath);
|
|
115
|
-
await flushDirectory();
|
|
116
|
-
}
|
|
117
|
-
throw cause;
|
|
118
|
-
});
|
|
119
|
-
try {
|
|
120
|
-
const checkTargetRoot = priorFile ? checkRoot : verifyRoot;
|
|
121
|
-
const { stat: fileStat } = await verifyCreationFile(file, target, path.join(root, DEFAULT_IGNORE_FILENAME), [starter], () => {
|
|
122
|
-
checkTargetRoot();
|
|
123
|
-
assertCurrent(markerPath, markerStat);
|
|
124
|
-
}, priorFile);
|
|
125
|
-
await flushDirectory();
|
|
126
|
-
checkTargetRoot();
|
|
127
|
-
assertCurrent(target, fileStat);
|
|
128
|
-
assertCurrent(markerPath, markerStat);
|
|
129
|
-
unlinkSync(markerPath);
|
|
130
|
-
await flushDirectory();
|
|
131
|
-
checkRoot();
|
|
132
|
-
const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
|
|
133
|
-
checkRoot();
|
|
134
|
-
if (source.identity !== ignoreFileIdentity(fileStat) || source.text !== starter.toString("utf8")) {
|
|
135
|
-
changed(DEFAULT_IGNORE_FILENAME);
|
|
136
|
-
}
|
|
137
|
-
return { source, created: priorFile === undefined };
|
|
138
|
-
}
|
|
139
|
-
finally {
|
|
140
|
-
await file.close();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
finally {
|
|
144
|
-
await marker.close();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
await directory?.close();
|
|
149
|
-
signal?.throwIfAborted();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch (cause) {
|
|
153
|
-
signal?.throwIfAborted();
|
|
154
|
-
if (cause instanceof AutomaticIgnoreCreationUnavailable)
|
|
155
|
-
throw cause;
|
|
156
|
-
const code = cause.code;
|
|
157
|
-
const detail = code === "EEXIST"
|
|
158
|
-
? "a file or creation record appeared concurrently; review the current files and retry"
|
|
159
|
-
: code
|
|
160
|
-
? "could not safely create or flush the file"
|
|
161
|
-
: cause.message;
|
|
162
|
-
throw new Error(`Ignore file "${DEFAULT_IGNORE_FILENAME}" initialization: ${detail}.`, { cause });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function checkCreationError(error) {
|
|
166
|
-
if (["EACCES", "EPERM", "EROFS", "ENOTSUP", "EOPNOTSUPP"].includes(error.code ?? "")) {
|
|
167
|
-
throw new AutomaticIgnoreCreationUnavailable("the filesystem does not permit automatic creation", { cause: error });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async function checkCreationAccess(root) {
|
|
171
|
-
try {
|
|
172
|
-
await fs.access(root, constants.W_OK);
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
checkCreationError(error);
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function assertRoot(root, expected) {
|
|
180
|
-
const current = lstatSync(root, { bigint: true });
|
|
181
|
-
if (!current.isDirectory() || !sameIdentity(expected, current) || realpathSync(root) !== root) {
|
|
182
|
-
throw new Error("the Pi agent directory is not canonical or changed during initialization");
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async function openCreationDirectory(root, expected) {
|
|
186
|
-
if (process.platform === "win32")
|
|
187
|
-
return { anchor: root };
|
|
188
|
-
const directory = await fs.open(root, openRead | (constants.O_DIRECTORY ?? 0));
|
|
189
|
-
try {
|
|
190
|
-
if (!sameIdentity(expected, await directory.stat({ bigint: true })))
|
|
191
|
-
changed("Pi agent directory");
|
|
192
|
-
return { directory, anchor: (await directoryAnchor(directory, expected)) ?? root };
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
await directory.close();
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function syncCreationDirectory(directory) {
|
|
200
|
-
if (!directory)
|
|
201
|
-
return async () => { };
|
|
202
|
-
try {
|
|
203
|
-
await directory.sync();
|
|
204
|
-
return () => directory.sync();
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
if (["EBADF", "EINVAL", "ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EPERM"].includes(error.code ?? "")) {
|
|
208
|
-
if (process.platform === "darwin")
|
|
209
|
-
return async () => { };
|
|
210
|
-
throw new AutomaticIgnoreCreationUnavailable("the filesystem does not support flushing the Pi agent directory");
|
|
211
|
-
}
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
async function directoryAnchor(directory, expected) {
|
|
216
|
-
for (const base of ["/proc/self/fd", "/dev/fd"]) {
|
|
217
|
-
const candidate = `${base}/${directory.fd}`;
|
|
218
|
-
const observed = await fs.stat(`${candidate}/.`, { bigint: true }).catch((error) => {
|
|
219
|
-
if (["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(error.code ?? ""))
|
|
220
|
-
return undefined;
|
|
221
|
-
throw error;
|
|
222
|
-
});
|
|
223
|
-
if (observed?.isDirectory() && sameIdentity(expected, observed))
|
|
224
|
-
return candidate;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
function statAt(target) {
|
|
228
|
-
return lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
229
|
-
}
|
|
230
|
-
function changed(name) {
|
|
231
|
-
throw new Error(`"${name}" changed during initialization; review the current files and retry`);
|
|
232
|
-
}
|
|
233
|
-
function assertCurrent(target, expected) {
|
|
234
|
-
const current = statAt(target);
|
|
235
|
-
if (!current || !sameFile(expected, current))
|
|
236
|
-
changed(path.basename(target));
|
|
237
|
-
}
|
|
238
|
-
function assertOwned(stat, name, privateRecord) {
|
|
239
|
-
if (!stat.isFile() ||
|
|
240
|
-
stat.nlink !== 1n ||
|
|
241
|
-
(process.getuid && stat.uid !== BigInt(process.getuid())) ||
|
|
242
|
-
(privateRecord && process.platform !== "win32" && (stat.mode & 63n) !== 0n)) {
|
|
243
|
-
throw new Error(`unsafe "${name}"; preserve it for manual recovery`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async function verifyCreationFile(handle, target, canonical, expected, checkRoot, prior, persist = true) {
|
|
247
|
-
const name = path.basename(target);
|
|
248
|
-
const privateRecord = name === DEFAULT_IGNORE_CREATION_RECORD;
|
|
249
|
-
const opened = await handle.stat({ bigint: true });
|
|
250
|
-
assertOwned(opened, name, privateRecord);
|
|
251
|
-
if (prior && !sameFile(prior, opened))
|
|
252
|
-
changed(name);
|
|
253
|
-
checkRoot();
|
|
254
|
-
if ((await fs.realpath(target)) !== canonical)
|
|
255
|
-
throw new Error(`use the exact on-disk filename "${name}"`);
|
|
256
|
-
checkRoot();
|
|
257
|
-
assertCurrent(target, opened);
|
|
258
|
-
if (!prior && persist)
|
|
259
|
-
await handle.writeFile(expected[0]);
|
|
260
|
-
const before = await handle.stat({ bigint: true });
|
|
261
|
-
assertOwned(before, name, privateRecord);
|
|
262
|
-
if (!(prior ? sameFile(opened, before) : sameIdentity(opened, before)))
|
|
263
|
-
changed(name);
|
|
264
|
-
checkRoot();
|
|
265
|
-
assertCurrent(target, before);
|
|
266
|
-
const observed = Buffer.alloc(Math.max(...expected.map((bytes) => bytes.length)) + 1);
|
|
267
|
-
let count = 0;
|
|
268
|
-
while (count < observed.length) {
|
|
269
|
-
checkRoot();
|
|
270
|
-
const { bytesRead } = await handle.read(observed, count, observed.length - count, count);
|
|
271
|
-
if (bytesRead === 0)
|
|
272
|
-
break;
|
|
273
|
-
count += bytesRead;
|
|
274
|
-
}
|
|
275
|
-
const bytes = expected.find((candidate) => observed.subarray(0, count).equals(candidate));
|
|
276
|
-
if (!bytes) {
|
|
277
|
-
throw new Error(privateRecord
|
|
278
|
-
? `invalid creation record "${name}"; preserve it for manual recovery`
|
|
279
|
-
: `unfinished creation of "${name}"; move the incomplete file outside the Pi agent directory or restore the full starter rules recorded in "${DEFAULT_IGNORE_CREATION_RECORD}", then retry confirmed setup or migration`);
|
|
280
|
-
}
|
|
281
|
-
if (persist)
|
|
282
|
-
await handle.sync();
|
|
283
|
-
if (!sameFile(before, await handle.stat({ bigint: true })))
|
|
284
|
-
changed(name);
|
|
285
|
-
checkRoot();
|
|
286
|
-
assertCurrent(target, before);
|
|
287
|
-
return { stat: before, bytes };
|
|
288
|
-
}
|