zen-fs-config 0.7.8 → 0.7.10
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.
|
@@ -1,3 +1,150 @@
|
|
|
1
|
+
// src/idb-repair.ts
|
|
2
|
+
var INODE_SIZE = 4096;
|
|
3
|
+
var S_IFMT = 61440;
|
|
4
|
+
var S_IFDIR = 16384;
|
|
5
|
+
var LEGACY_LISTING_MAGIC = 123;
|
|
6
|
+
function idb() {
|
|
7
|
+
return globalThis.indexedDB;
|
|
8
|
+
}
|
|
9
|
+
function traceLog() {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
try {
|
|
12
|
+
if (!Array.isArray(g.__zenfsIdbRepair)) g.__zenfsIdbRepair = [];
|
|
13
|
+
return g.__zenfsIdbRepair;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function openDB(name) {
|
|
19
|
+
const factory = idb();
|
|
20
|
+
if (!factory) return Promise.resolve(null);
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
let req;
|
|
23
|
+
try {
|
|
24
|
+
req = factory.open(name);
|
|
25
|
+
} catch {
|
|
26
|
+
resolve(null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
req.onupgradeneeded = () => {
|
|
30
|
+
try {
|
|
31
|
+
req.transaction?.abort();
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
req.onsuccess = () => resolve(req.result);
|
|
36
|
+
req.onerror = () => resolve(null);
|
|
37
|
+
req.onblocked = () => resolve(null);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
var request = (req) => new Promise((resolve, reject) => {
|
|
41
|
+
req.onsuccess = () => resolve(req.result);
|
|
42
|
+
req.onerror = () => reject(req.error);
|
|
43
|
+
});
|
|
44
|
+
function isDecodableListing(bytes) {
|
|
45
|
+
if (bytes.length === 0) return false;
|
|
46
|
+
if (bytes[0] !== LEGACY_LISTING_MAGIC) return true;
|
|
47
|
+
let text;
|
|
48
|
+
try {
|
|
49
|
+
text = new TextDecoder().decode(bytes);
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
let parsed;
|
|
54
|
+
try {
|
|
55
|
+
parsed = JSON.parse(text);
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
60
|
+
return Object.values(parsed).every(
|
|
61
|
+
(v) => typeof v === "number" || typeof v === "string" && /^\d+$/.test(v)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function isDirectoryInode(bytes, key) {
|
|
65
|
+
if (bytes.byteLength !== INODE_SIZE) return null;
|
|
66
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
67
|
+
const ino = view.getUint32(58, true);
|
|
68
|
+
if (ino !== key) return null;
|
|
69
|
+
const mode = view.getUint16(12, true);
|
|
70
|
+
if ((mode & S_IFMT) !== S_IFDIR) return null;
|
|
71
|
+
const mtime = view.getFloat64(42, true);
|
|
72
|
+
if (!Number.isFinite(mtime) || mtime < 1e11 || mtime > 1e13) return null;
|
|
73
|
+
return view.getUint32(0, true);
|
|
74
|
+
}
|
|
75
|
+
async function repairIndexedDBStore(storeName) {
|
|
76
|
+
const trace = traceLog();
|
|
77
|
+
const note = (phase, extra) => {
|
|
78
|
+
if (!trace) return;
|
|
79
|
+
trace.push({ store: storeName, phase, at: Date.now(), ...extra ?? {} });
|
|
80
|
+
};
|
|
81
|
+
note("start");
|
|
82
|
+
if (!idb()) {
|
|
83
|
+
note("skip: no indexedDB");
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const db = await openDB(storeName);
|
|
87
|
+
if (!db) {
|
|
88
|
+
note("skip: db not opened");
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const objectStoreName = Array.from(
|
|
92
|
+
db.objectStoreNames
|
|
93
|
+
)[0];
|
|
94
|
+
if (!objectStoreName) {
|
|
95
|
+
note("skip: no object store");
|
|
96
|
+
db.close?.();
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const result = { scanned: 0, repaired: 0, details: [] };
|
|
100
|
+
try {
|
|
101
|
+
const tx = db.transaction(objectStoreName, "readwrite");
|
|
102
|
+
const done = new Promise((resolve, reject) => {
|
|
103
|
+
tx.oncomplete = () => resolve();
|
|
104
|
+
tx.onerror = () => reject(tx.error);
|
|
105
|
+
tx.onabort = () => reject(tx.error);
|
|
106
|
+
});
|
|
107
|
+
const store = tx.objectStore(objectStoreName);
|
|
108
|
+
const keys = await request(store.getAllKeys());
|
|
109
|
+
const values = await request(store.getAll());
|
|
110
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
111
|
+
for (let i = 0; i < keys.length; i++) {
|
|
112
|
+
const value = values[i];
|
|
113
|
+
if (value instanceof Uint8Array) byKey.set(Number(keys[i]), value);
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i < keys.length; i++) {
|
|
116
|
+
const value = values[i];
|
|
117
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
118
|
+
const key = Number(keys[i]);
|
|
119
|
+
if (!Number.isFinite(key)) continue;
|
|
120
|
+
result.scanned++;
|
|
121
|
+
const dataSlot = isDirectoryInode(value, key);
|
|
122
|
+
if (dataSlot === null) continue;
|
|
123
|
+
const listing = byKey.get(dataSlot);
|
|
124
|
+
if (listing && isDecodableListing(listing)) continue;
|
|
125
|
+
const reason = listing ? "listing slot holds non-listing bytes" : "listing slot missing";
|
|
126
|
+
result.repaired++;
|
|
127
|
+
result.details.push({ key, data: dataSlot, reason });
|
|
128
|
+
await request(store.put(new TextEncoder().encode("{}"), dataSlot));
|
|
129
|
+
}
|
|
130
|
+
await done;
|
|
131
|
+
note("done", { scanned: result.scanned, repaired: result.repaired });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
note("error", { message: err instanceof Error ? `${err.name}: ${err.message}` : String(err) });
|
|
134
|
+
try {
|
|
135
|
+
db.close?.();
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
} finally {
|
|
140
|
+
try {
|
|
141
|
+
db.close?.();
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
1
148
|
// src/backend-registry.ts
|
|
2
149
|
var registry = /* @__PURE__ */ new Map();
|
|
3
150
|
var metadataRegistry = /* @__PURE__ */ new Map();
|
|
@@ -164,6 +311,12 @@ registerBackend("IndexedDB", async (options) => {
|
|
|
164
311
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
165
312
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
166
313
|
const label = options.label ?? storeName;
|
|
314
|
+
const repaired = await repairIndexedDBStore(storeName);
|
|
315
|
+
if (repaired?.repaired) {
|
|
316
|
+
console.warn(
|
|
317
|
+
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
318
|
+
);
|
|
319
|
+
}
|
|
167
320
|
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
168
321
|
}, {
|
|
169
322
|
type: "IndexedDB",
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,159 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
+
// src/idb-repair.ts
|
|
34
|
+
function idb() {
|
|
35
|
+
return globalThis.indexedDB;
|
|
36
|
+
}
|
|
37
|
+
function traceLog() {
|
|
38
|
+
const g = globalThis;
|
|
39
|
+
try {
|
|
40
|
+
if (!Array.isArray(g.__zenfsIdbRepair)) g.__zenfsIdbRepair = [];
|
|
41
|
+
return g.__zenfsIdbRepair;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function openDB(name) {
|
|
47
|
+
const factory = idb();
|
|
48
|
+
if (!factory) return Promise.resolve(null);
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
let req;
|
|
51
|
+
try {
|
|
52
|
+
req = factory.open(name);
|
|
53
|
+
} catch {
|
|
54
|
+
resolve(null);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
req.onupgradeneeded = () => {
|
|
58
|
+
try {
|
|
59
|
+
req.transaction?.abort();
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
req.onsuccess = () => resolve(req.result);
|
|
64
|
+
req.onerror = () => resolve(null);
|
|
65
|
+
req.onblocked = () => resolve(null);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function isDecodableListing(bytes) {
|
|
69
|
+
if (bytes.length === 0) return false;
|
|
70
|
+
if (bytes[0] !== LEGACY_LISTING_MAGIC) return true;
|
|
71
|
+
let text;
|
|
72
|
+
try {
|
|
73
|
+
text = new TextDecoder().decode(bytes);
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(text);
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
84
|
+
return Object.values(parsed).every(
|
|
85
|
+
(v) => typeof v === "number" || typeof v === "string" && /^\d+$/.test(v)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function isDirectoryInode(bytes, key) {
|
|
89
|
+
if (bytes.byteLength !== INODE_SIZE) return null;
|
|
90
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
91
|
+
const ino = view.getUint32(58, true);
|
|
92
|
+
if (ino !== key) return null;
|
|
93
|
+
const mode = view.getUint16(12, true);
|
|
94
|
+
if ((mode & S_IFMT) !== S_IFDIR) return null;
|
|
95
|
+
const mtime = view.getFloat64(42, true);
|
|
96
|
+
if (!Number.isFinite(mtime) || mtime < 1e11 || mtime > 1e13) return null;
|
|
97
|
+
return view.getUint32(0, true);
|
|
98
|
+
}
|
|
99
|
+
async function repairIndexedDBStore(storeName) {
|
|
100
|
+
const trace = traceLog();
|
|
101
|
+
const note = (phase, extra) => {
|
|
102
|
+
if (!trace) return;
|
|
103
|
+
trace.push({ store: storeName, phase, at: Date.now(), ...extra ?? {} });
|
|
104
|
+
};
|
|
105
|
+
note("start");
|
|
106
|
+
if (!idb()) {
|
|
107
|
+
note("skip: no indexedDB");
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const db = await openDB(storeName);
|
|
111
|
+
if (!db) {
|
|
112
|
+
note("skip: db not opened");
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const objectStoreName = Array.from(
|
|
116
|
+
db.objectStoreNames
|
|
117
|
+
)[0];
|
|
118
|
+
if (!objectStoreName) {
|
|
119
|
+
note("skip: no object store");
|
|
120
|
+
db.close?.();
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const result = { scanned: 0, repaired: 0, details: [] };
|
|
124
|
+
try {
|
|
125
|
+
const tx = db.transaction(objectStoreName, "readwrite");
|
|
126
|
+
const done = new Promise((resolve, reject) => {
|
|
127
|
+
tx.oncomplete = () => resolve();
|
|
128
|
+
tx.onerror = () => reject(tx.error);
|
|
129
|
+
tx.onabort = () => reject(tx.error);
|
|
130
|
+
});
|
|
131
|
+
const store = tx.objectStore(objectStoreName);
|
|
132
|
+
const keys = await request(store.getAllKeys());
|
|
133
|
+
const values = await request(store.getAll());
|
|
134
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
135
|
+
for (let i = 0; i < keys.length; i++) {
|
|
136
|
+
const value = values[i];
|
|
137
|
+
if (value instanceof Uint8Array) byKey.set(Number(keys[i]), value);
|
|
138
|
+
}
|
|
139
|
+
for (let i = 0; i < keys.length; i++) {
|
|
140
|
+
const value = values[i];
|
|
141
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
142
|
+
const key = Number(keys[i]);
|
|
143
|
+
if (!Number.isFinite(key)) continue;
|
|
144
|
+
result.scanned++;
|
|
145
|
+
const dataSlot = isDirectoryInode(value, key);
|
|
146
|
+
if (dataSlot === null) continue;
|
|
147
|
+
const listing = byKey.get(dataSlot);
|
|
148
|
+
if (listing && isDecodableListing(listing)) continue;
|
|
149
|
+
const reason = listing ? "listing slot holds non-listing bytes" : "listing slot missing";
|
|
150
|
+
result.repaired++;
|
|
151
|
+
result.details.push({ key, data: dataSlot, reason });
|
|
152
|
+
await request(store.put(new TextEncoder().encode("{}"), dataSlot));
|
|
153
|
+
}
|
|
154
|
+
await done;
|
|
155
|
+
note("done", { scanned: result.scanned, repaired: result.repaired });
|
|
156
|
+
} catch (err) {
|
|
157
|
+
note("error", { message: err instanceof Error ? `${err.name}: ${err.message}` : String(err) });
|
|
158
|
+
try {
|
|
159
|
+
db.close?.();
|
|
160
|
+
} catch {
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
} finally {
|
|
164
|
+
try {
|
|
165
|
+
db.close?.();
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
var INODE_SIZE, S_IFMT, S_IFDIR, LEGACY_LISTING_MAGIC, request;
|
|
172
|
+
var init_idb_repair = __esm({
|
|
173
|
+
"src/idb-repair.ts"() {
|
|
174
|
+
"use strict";
|
|
175
|
+
INODE_SIZE = 4096;
|
|
176
|
+
S_IFMT = 61440;
|
|
177
|
+
S_IFDIR = 16384;
|
|
178
|
+
LEGACY_LISTING_MAGIC = 123;
|
|
179
|
+
request = (req) => new Promise((resolve, reject) => {
|
|
180
|
+
req.onsuccess = () => resolve(req.result);
|
|
181
|
+
req.onerror = () => reject(req.error);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
33
186
|
// src/backend-registry.ts
|
|
34
187
|
var backend_registry_exports = {};
|
|
35
188
|
__export(backend_registry_exports, {
|
|
@@ -267,6 +420,7 @@ var registry, metadataRegistry, inMemoryCounter, _memCache, OPTIONAL_BACKEND_GLO
|
|
|
267
420
|
var init_backend_registry = __esm({
|
|
268
421
|
"src/backend-registry.ts"() {
|
|
269
422
|
"use strict";
|
|
423
|
+
init_idb_repair();
|
|
270
424
|
registry = /* @__PURE__ */ new Map();
|
|
271
425
|
metadataRegistry = /* @__PURE__ */ new Map();
|
|
272
426
|
inMemoryCounter = 0;
|
|
@@ -291,6 +445,12 @@ var init_backend_registry = __esm({
|
|
|
291
445
|
const { IndexedDB } = await import("@zenfs/dom");
|
|
292
446
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
293
447
|
const label = options.label ?? storeName;
|
|
448
|
+
const repaired = await repairIndexedDBStore(storeName);
|
|
449
|
+
if (repaired?.repaired) {
|
|
450
|
+
console.warn(
|
|
451
|
+
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
452
|
+
);
|
|
453
|
+
}
|
|
294
454
|
return wrapZenFSFileSystem({ backend: IndexedDB, storeName, label });
|
|
295
455
|
}, {
|
|
296
456
|
type: "IndexedDB",
|
|
@@ -1153,8 +1313,8 @@ function isLocalStorageUnavailableError(err) {
|
|
|
1153
1313
|
}
|
|
1154
1314
|
function deleteDataGroupLocalStore(appId, groupId, options = {}) {
|
|
1155
1315
|
const storeName = dataGroupLocalStoreName(appId, groupId);
|
|
1156
|
-
const
|
|
1157
|
-
if (!
|
|
1316
|
+
const idb2 = globalThis.indexedDB;
|
|
1317
|
+
if (!idb2 || typeof idb2.deleteDatabase !== "function") {
|
|
1158
1318
|
return Promise.resolve({
|
|
1159
1319
|
storeName,
|
|
1160
1320
|
deleted: false,
|
|
@@ -1174,21 +1334,21 @@ function deleteDataGroupLocalStore(appId, groupId, options = {}) {
|
|
|
1174
1334
|
if (timer) clearTimeout(timer);
|
|
1175
1335
|
resolve(result);
|
|
1176
1336
|
};
|
|
1177
|
-
let
|
|
1337
|
+
let request2;
|
|
1178
1338
|
try {
|
|
1179
|
-
|
|
1339
|
+
request2 = idb2.deleteDatabase(storeName);
|
|
1180
1340
|
} catch (err) {
|
|
1181
1341
|
finish({ storeName, deleted: false, blocked: false, error: summarizeError(err).message });
|
|
1182
1342
|
return;
|
|
1183
1343
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1344
|
+
request2.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
|
|
1345
|
+
request2.onerror = () => finish({
|
|
1186
1346
|
storeName,
|
|
1187
1347
|
deleted: false,
|
|
1188
1348
|
blocked: false,
|
|
1189
|
-
error: summarizeError(
|
|
1349
|
+
error: summarizeError(request2.error).message
|
|
1190
1350
|
});
|
|
1191
|
-
|
|
1351
|
+
request2.onblocked = () => {
|
|
1192
1352
|
blocked = true;
|
|
1193
1353
|
};
|
|
1194
1354
|
timer = setTimeout(() => {
|
|
@@ -2289,9 +2449,9 @@ function pickInstanceId(descriptor) {
|
|
|
2289
2449
|
function isMtimeSidecar(fileName) {
|
|
2290
2450
|
return fileName.endsWith(".mtime");
|
|
2291
2451
|
}
|
|
2292
|
-
var
|
|
2452
|
+
var S_IFDIR2 = 16384;
|
|
2293
2453
|
function isDirectory(stat) {
|
|
2294
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2454
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR2) === S_IFDIR2;
|
|
2295
2455
|
}
|
|
2296
2456
|
function joinPath(dir, entry) {
|
|
2297
2457
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -2343,10 +2503,10 @@ async function purgeMtimeSidecars(fs, options = {}) {
|
|
|
2343
2503
|
function isKeepFile(fileName) {
|
|
2344
2504
|
return fileName === ".keep";
|
|
2345
2505
|
}
|
|
2346
|
-
var
|
|
2506
|
+
var S_IFDIR3 = 16384;
|
|
2347
2507
|
var DEFAULT_PROTECTED_DIRS = ["/.meta/backends/.keep"];
|
|
2348
2508
|
function isDirectory2(stat) {
|
|
2349
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2509
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR3) === S_IFDIR3;
|
|
2350
2510
|
}
|
|
2351
2511
|
function joinPath2(dir, entry) {
|
|
2352
2512
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -2404,9 +2564,9 @@ async function purgeKeepFiles(fs, options = {}) {
|
|
|
2404
2564
|
}
|
|
2405
2565
|
|
|
2406
2566
|
// src/version-migration.ts
|
|
2407
|
-
var
|
|
2567
|
+
var S_IFDIR4 = 16384;
|
|
2408
2568
|
function isDir(stat) {
|
|
2409
|
-
return typeof stat.mode === "number" && (stat.mode &
|
|
2569
|
+
return typeof stat.mode === "number" && (stat.mode & S_IFDIR4) === S_IFDIR4;
|
|
2410
2570
|
}
|
|
2411
2571
|
function joinPath3(dir, entry) {
|
|
2412
2572
|
if (dir === "/" || dir === "") return `/${entry}`;
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
registerBackend,
|
|
10
10
|
unregisterBackend,
|
|
11
11
|
wrapZenFSFileSystem
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QBBPUTC7.mjs";
|
|
13
13
|
|
|
14
14
|
// src/config-repo.ts
|
|
15
15
|
import {
|
|
@@ -465,7 +465,7 @@ function registerFolderBackend() {
|
|
|
465
465
|
const pathMod = await import("path");
|
|
466
466
|
const dir = options.path;
|
|
467
467
|
const store = new FolderStore({ path: dir, label: options.label, fs, pathMod });
|
|
468
|
-
return (await import("./backend-registry-
|
|
468
|
+
return (await import("./backend-registry-OZ4XU76Z.mjs")).wrapZenFSFileSystem({ backend: FolderBackend, path: dir, label: options.label });
|
|
469
469
|
},
|
|
470
470
|
{
|
|
471
471
|
type: "Folder",
|
package/dist/zen-fs-config.js
CHANGED
|
@@ -49,6 +49,159 @@ var ZenFSConfig = (() => {
|
|
|
49
49
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
50
50
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
51
51
|
|
|
52
|
+
// src/idb-repair.ts
|
|
53
|
+
function idb() {
|
|
54
|
+
return globalThis.indexedDB;
|
|
55
|
+
}
|
|
56
|
+
function traceLog() {
|
|
57
|
+
const g = globalThis;
|
|
58
|
+
try {
|
|
59
|
+
if (!Array.isArray(g.__zenfsIdbRepair)) g.__zenfsIdbRepair = [];
|
|
60
|
+
return g.__zenfsIdbRepair;
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function openDB(name) {
|
|
66
|
+
const factory = idb();
|
|
67
|
+
if (!factory) return Promise.resolve(null);
|
|
68
|
+
return new Promise((resolve4) => {
|
|
69
|
+
let req;
|
|
70
|
+
try {
|
|
71
|
+
req = factory.open(name);
|
|
72
|
+
} catch {
|
|
73
|
+
resolve4(null);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
req.onupgradeneeded = () => {
|
|
77
|
+
try {
|
|
78
|
+
req.transaction?.abort();
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
req.onsuccess = () => resolve4(req.result);
|
|
83
|
+
req.onerror = () => resolve4(null);
|
|
84
|
+
req.onblocked = () => resolve4(null);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function isDecodableListing(bytes) {
|
|
88
|
+
if (bytes.length === 0) return false;
|
|
89
|
+
if (bytes[0] !== LEGACY_LISTING_MAGIC) return true;
|
|
90
|
+
let text;
|
|
91
|
+
try {
|
|
92
|
+
text = new TextDecoder().decode(bytes);
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
let parsed;
|
|
97
|
+
try {
|
|
98
|
+
parsed = JSON.parse(text);
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
103
|
+
return Object.values(parsed).every(
|
|
104
|
+
(v) => typeof v === "number" || typeof v === "string" && /^\d+$/.test(v)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function isDirectoryInode(bytes, key) {
|
|
108
|
+
if (bytes.byteLength !== INODE_SIZE) return null;
|
|
109
|
+
const view2 = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
110
|
+
const ino = view2.getUint32(58, true);
|
|
111
|
+
if (ino !== key) return null;
|
|
112
|
+
const mode = view2.getUint16(12, true);
|
|
113
|
+
if ((mode & S_IFMT) !== S_IFDIR) return null;
|
|
114
|
+
const mtime = view2.getFloat64(42, true);
|
|
115
|
+
if (!Number.isFinite(mtime) || mtime < 1e11 || mtime > 1e13) return null;
|
|
116
|
+
return view2.getUint32(0, true);
|
|
117
|
+
}
|
|
118
|
+
async function repairIndexedDBStore(storeName) {
|
|
119
|
+
const trace = traceLog();
|
|
120
|
+
const note = (phase, extra) => {
|
|
121
|
+
if (!trace) return;
|
|
122
|
+
trace.push({ store: storeName, phase, at: Date.now(), ...extra ?? {} });
|
|
123
|
+
};
|
|
124
|
+
note("start");
|
|
125
|
+
if (!idb()) {
|
|
126
|
+
note("skip: no indexedDB");
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const db = await openDB(storeName);
|
|
130
|
+
if (!db) {
|
|
131
|
+
note("skip: db not opened");
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const objectStoreName = Array.from(
|
|
135
|
+
db.objectStoreNames
|
|
136
|
+
)[0];
|
|
137
|
+
if (!objectStoreName) {
|
|
138
|
+
note("skip: no object store");
|
|
139
|
+
db.close?.();
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const result = { scanned: 0, repaired: 0, details: [] };
|
|
143
|
+
try {
|
|
144
|
+
const tx = db.transaction(objectStoreName, "readwrite");
|
|
145
|
+
const done = new Promise((resolve4, reject) => {
|
|
146
|
+
tx.oncomplete = () => resolve4();
|
|
147
|
+
tx.onerror = () => reject(tx.error);
|
|
148
|
+
tx.onabort = () => reject(tx.error);
|
|
149
|
+
});
|
|
150
|
+
const store = tx.objectStore(objectStoreName);
|
|
151
|
+
const keys = await request(store.getAllKeys());
|
|
152
|
+
const values = await request(store.getAll());
|
|
153
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
154
|
+
for (let i = 0; i < keys.length; i++) {
|
|
155
|
+
const value = values[i];
|
|
156
|
+
if (value instanceof Uint8Array) byKey.set(Number(keys[i]), value);
|
|
157
|
+
}
|
|
158
|
+
for (let i = 0; i < keys.length; i++) {
|
|
159
|
+
const value = values[i];
|
|
160
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
161
|
+
const key = Number(keys[i]);
|
|
162
|
+
if (!Number.isFinite(key)) continue;
|
|
163
|
+
result.scanned++;
|
|
164
|
+
const dataSlot = isDirectoryInode(value, key);
|
|
165
|
+
if (dataSlot === null) continue;
|
|
166
|
+
const listing = byKey.get(dataSlot);
|
|
167
|
+
if (listing && isDecodableListing(listing)) continue;
|
|
168
|
+
const reason = listing ? "listing slot holds non-listing bytes" : "listing slot missing";
|
|
169
|
+
result.repaired++;
|
|
170
|
+
result.details.push({ key, data: dataSlot, reason });
|
|
171
|
+
await request(store.put(new TextEncoder().encode("{}"), dataSlot));
|
|
172
|
+
}
|
|
173
|
+
await done;
|
|
174
|
+
note("done", { scanned: result.scanned, repaired: result.repaired });
|
|
175
|
+
} catch (err2) {
|
|
176
|
+
note("error", { message: err2 instanceof Error ? `${err2.name}: ${err2.message}` : String(err2) });
|
|
177
|
+
try {
|
|
178
|
+
db.close?.();
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
} finally {
|
|
183
|
+
try {
|
|
184
|
+
db.close?.();
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
var INODE_SIZE, S_IFMT, S_IFDIR, LEGACY_LISTING_MAGIC, request;
|
|
191
|
+
var init_idb_repair = __esm({
|
|
192
|
+
"src/idb-repair.ts"() {
|
|
193
|
+
"use strict";
|
|
194
|
+
INODE_SIZE = 4096;
|
|
195
|
+
S_IFMT = 61440;
|
|
196
|
+
S_IFDIR = 16384;
|
|
197
|
+
LEGACY_LISTING_MAGIC = 123;
|
|
198
|
+
request = (req) => new Promise((resolve4, reject) => {
|
|
199
|
+
req.onsuccess = () => resolve4(req.result);
|
|
200
|
+
req.onerror = () => reject(req.error);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
52
205
|
// node_modules/utilium/dist/array.js
|
|
53
206
|
var init_array = __esm({
|
|
54
207
|
"node_modules/utilium/dist/array.js"() {
|
|
@@ -1478,10 +1631,10 @@ var ZenFSConfig = (() => {
|
|
|
1478
1631
|
R_OK: () => R_OK,
|
|
1479
1632
|
S_IFBLK: () => S_IFBLK,
|
|
1480
1633
|
S_IFCHR: () => S_IFCHR,
|
|
1481
|
-
S_IFDIR: () =>
|
|
1634
|
+
S_IFDIR: () => S_IFDIR2,
|
|
1482
1635
|
S_IFIFO: () => S_IFIFO,
|
|
1483
1636
|
S_IFLNK: () => S_IFLNK,
|
|
1484
|
-
S_IFMT: () =>
|
|
1637
|
+
S_IFMT: () => S_IFMT2,
|
|
1485
1638
|
S_IFREG: () => S_IFREG,
|
|
1486
1639
|
S_IFSOCK: () => S_IFSOCK,
|
|
1487
1640
|
S_IRGRP: () => S_IRGRP,
|
|
@@ -1504,7 +1657,7 @@ var ZenFSConfig = (() => {
|
|
|
1504
1657
|
X_OK: () => X_OK,
|
|
1505
1658
|
size_max: () => size_max
|
|
1506
1659
|
});
|
|
1507
|
-
var F_OK, R_OK, W_OK, X_OK, COPYFILE_EXCL, COPYFILE_FICLONE, COPYFILE_FICLONE_FORCE, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, O_DIRECTORY, O_NOATIME, O_NOFOLLOW, O_SYNC, O_DSYNC, O_SYMLINK, O_DIRECT, O_NONBLOCK,
|
|
1660
|
+
var F_OK, R_OK, W_OK, X_OK, COPYFILE_EXCL, COPYFILE_FICLONE, COPYFILE_FICLONE_FORCE, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, O_DIRECTORY, O_NOATIME, O_NOFOLLOW, O_SYNC, O_DSYNC, O_SYMLINK, O_DIRECT, O_NONBLOCK, S_IFMT2, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR2, S_IFCHR, S_IFIFO, S_ISUID, S_ISGID, S_ISVTX, S_IRWXU, S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXG, S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH, S_IWOTH, S_IXOTH, UV_FS_O_FILEMAP, size_max;
|
|
1508
1661
|
var init_constants = __esm({
|
|
1509
1662
|
"node_modules/@zenfs/core/dist/constants.js"() {
|
|
1510
1663
|
"use strict";
|
|
@@ -1531,12 +1684,12 @@ var ZenFSConfig = (() => {
|
|
|
1531
1684
|
O_SYMLINK = 32768;
|
|
1532
1685
|
O_DIRECT = 16384;
|
|
1533
1686
|
O_NONBLOCK = 2048;
|
|
1534
|
-
|
|
1687
|
+
S_IFMT2 = 61440;
|
|
1535
1688
|
S_IFSOCK = 49152;
|
|
1536
1689
|
S_IFLNK = 40960;
|
|
1537
1690
|
S_IFREG = 32768;
|
|
1538
1691
|
S_IFBLK = 24576;
|
|
1539
|
-
|
|
1692
|
+
S_IFDIR2 = 16384;
|
|
1540
1693
|
S_IFCHR = 8192;
|
|
1541
1694
|
S_IFIFO = 4096;
|
|
1542
1695
|
S_ISUID = 2048;
|
|
@@ -2906,7 +3059,7 @@ var ZenFSConfig = (() => {
|
|
|
2906
3059
|
this.size = this._convert(size ?? 0);
|
|
2907
3060
|
this.ino = this._convert(ino ?? 0);
|
|
2908
3061
|
this.mode = this._convert(mode ?? 420 & S_IFREG);
|
|
2909
|
-
if ((this.mode &
|
|
3062
|
+
if ((this.mode & S_IFMT2) == 0) {
|
|
2910
3063
|
this.mode = this.mode | this._convert(S_IFREG);
|
|
2911
3064
|
}
|
|
2912
3065
|
Object.assign(this, rest);
|
|
@@ -2944,25 +3097,25 @@ var ZenFSConfig = (() => {
|
|
|
2944
3097
|
this.birthtimeMs = this._convert(value.getTime());
|
|
2945
3098
|
}
|
|
2946
3099
|
isFile() {
|
|
2947
|
-
return (this.mode &
|
|
3100
|
+
return (this.mode & S_IFMT2) === S_IFREG;
|
|
2948
3101
|
}
|
|
2949
3102
|
isDirectory() {
|
|
2950
|
-
return (this.mode &
|
|
3103
|
+
return (this.mode & S_IFMT2) === S_IFDIR2;
|
|
2951
3104
|
}
|
|
2952
3105
|
isSymbolicLink() {
|
|
2953
|
-
return (this.mode &
|
|
3106
|
+
return (this.mode & S_IFMT2) === S_IFLNK;
|
|
2954
3107
|
}
|
|
2955
3108
|
isSocket() {
|
|
2956
|
-
return (this.mode &
|
|
3109
|
+
return (this.mode & S_IFMT2) === S_IFSOCK;
|
|
2957
3110
|
}
|
|
2958
3111
|
isBlockDevice() {
|
|
2959
|
-
return (this.mode &
|
|
3112
|
+
return (this.mode & S_IFMT2) === S_IFBLK;
|
|
2960
3113
|
}
|
|
2961
3114
|
isCharacterDevice() {
|
|
2962
|
-
return (this.mode &
|
|
3115
|
+
return (this.mode & S_IFMT2) === S_IFCHR;
|
|
2963
3116
|
}
|
|
2964
3117
|
isFIFO() {
|
|
2965
|
-
return (this.mode &
|
|
3118
|
+
return (this.mode & S_IFMT2) === S_IFIFO;
|
|
2966
3119
|
}
|
|
2967
3120
|
toJSON() {
|
|
2968
3121
|
return pick(this, _inode_fields);
|
|
@@ -3042,25 +3195,25 @@ var ZenFSConfig = (() => {
|
|
|
3042
3195
|
|
|
3043
3196
|
// node_modules/@zenfs/core/dist/internal/inode.js
|
|
3044
3197
|
function isFile2(metadata) {
|
|
3045
|
-
return (metadata.mode &
|
|
3198
|
+
return (metadata.mode & S_IFMT2) === S_IFREG;
|
|
3046
3199
|
}
|
|
3047
3200
|
function isDirectory2(metadata) {
|
|
3048
|
-
return (metadata.mode &
|
|
3201
|
+
return (metadata.mode & S_IFMT2) === S_IFDIR2;
|
|
3049
3202
|
}
|
|
3050
3203
|
function isSymbolicLink(metadata) {
|
|
3051
|
-
return (metadata.mode &
|
|
3204
|
+
return (metadata.mode & S_IFMT2) === S_IFLNK;
|
|
3052
3205
|
}
|
|
3053
3206
|
function isSocket(metadata) {
|
|
3054
|
-
return (metadata.mode &
|
|
3207
|
+
return (metadata.mode & S_IFMT2) === S_IFSOCK;
|
|
3055
3208
|
}
|
|
3056
3209
|
function isBlockDevice(metadata) {
|
|
3057
|
-
return (metadata.mode &
|
|
3210
|
+
return (metadata.mode & S_IFMT2) === S_IFBLK;
|
|
3058
3211
|
}
|
|
3059
3212
|
function isCharacterDevice(metadata) {
|
|
3060
|
-
return (metadata.mode &
|
|
3213
|
+
return (metadata.mode & S_IFMT2) === S_IFCHR;
|
|
3061
3214
|
}
|
|
3062
3215
|
function isFIFO(metadata) {
|
|
3063
|
-
return (metadata.mode &
|
|
3216
|
+
return (metadata.mode & S_IFMT2) === S_IFIFO;
|
|
3064
3217
|
}
|
|
3065
3218
|
function hasAccess($, inode, access3) {
|
|
3066
3219
|
const { credentials } = contextOf($);
|
|
@@ -3849,7 +4002,7 @@ var ZenFSConfig = (() => {
|
|
|
3849
4002
|
const node = this.get(path);
|
|
3850
4003
|
if (!node)
|
|
3851
4004
|
throw withErrno("ENOENT");
|
|
3852
|
-
if ((node.mode &
|
|
4005
|
+
if ((node.mode & S_IFMT2) != S_IFDIR2)
|
|
3853
4006
|
throw withErrno("ENOTDIR");
|
|
3854
4007
|
const entries2 = {};
|
|
3855
4008
|
for (const entry of this.keys()) {
|
|
@@ -3873,7 +4026,7 @@ var ZenFSConfig = (() => {
|
|
|
3873
4026
|
directories() {
|
|
3874
4027
|
const dirs = /* @__PURE__ */ new Map();
|
|
3875
4028
|
for (const [path, node] of this) {
|
|
3876
|
-
if ((node.mode &
|
|
4029
|
+
if ((node.mode & S_IFMT2) != S_IFDIR2)
|
|
3877
4030
|
continue;
|
|
3878
4031
|
const entries2 = {};
|
|
3879
4032
|
for (const entry of this.keys()) {
|
|
@@ -4562,7 +4715,7 @@ var ZenFSConfig = (() => {
|
|
|
4562
4715
|
const [path, ino] = queue.shift();
|
|
4563
4716
|
const inode = new Inode(await tx.get(ino));
|
|
4564
4717
|
index.set(path, inode);
|
|
4565
|
-
if (inode.mode &
|
|
4718
|
+
if (inode.mode & S_IFDIR2) {
|
|
4566
4719
|
const dir = decodeDirListing(await tx.get(inode.data) ?? _throw(withErrno("ENODATA")));
|
|
4567
4720
|
for (const [name, id] of Object.entries(dir)) {
|
|
4568
4721
|
queue.push([join(path, name), id]);
|
|
@@ -4591,7 +4744,7 @@ var ZenFSConfig = (() => {
|
|
|
4591
4744
|
const [path, ino] = queue.shift();
|
|
4592
4745
|
const inode = new Inode(tx.getSync(ino));
|
|
4593
4746
|
index.set(path, inode);
|
|
4594
|
-
if (inode.mode &
|
|
4747
|
+
if (inode.mode & S_IFDIR2) {
|
|
4595
4748
|
const dir = decodeDirListing(tx.getSync(inode.data) ?? _throw(withErrno("ENODATA")));
|
|
4596
4749
|
for (const [name, id] of Object.entries(dir)) {
|
|
4597
4750
|
queue.push([join(path, name), id]);
|
|
@@ -4767,10 +4920,10 @@ var ZenFSConfig = (() => {
|
|
|
4767
4920
|
this.removeSync(path, true);
|
|
4768
4921
|
}
|
|
4769
4922
|
async mkdir(path, options) {
|
|
4770
|
-
return await this.commitNew(path, { ...options, mode: options.mode |
|
|
4923
|
+
return await this.commitNew(path, { ...options, mode: options.mode | S_IFDIR2 }, encodeUTF8("{}"));
|
|
4771
4924
|
}
|
|
4772
4925
|
mkdirSync(path, options) {
|
|
4773
|
-
return this.commitNewSync(path, { ...options, mode: options.mode |
|
|
4926
|
+
return this.commitNewSync(path, { ...options, mode: options.mode | S_IFDIR2 }, encodeUTF8("{}"));
|
|
4774
4927
|
}
|
|
4775
4928
|
async readdir(path) {
|
|
4776
4929
|
const env_11 = { stack: [], error: void 0, hasError: false };
|
|
@@ -4956,7 +5109,7 @@ var ZenFSConfig = (() => {
|
|
|
4956
5109
|
const tx = __addDisposableResource(env_19, this.transaction(), true);
|
|
4957
5110
|
if (await tx.get(rootIno))
|
|
4958
5111
|
return;
|
|
4959
|
-
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 |
|
|
5112
|
+
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 | S_IFDIR2 });
|
|
4960
5113
|
await tx.set(inode.data, encodeUTF8("{}"));
|
|
4961
5114
|
this._add(rootIno, "/");
|
|
4962
5115
|
await tx.set(rootIno, inode);
|
|
@@ -4979,7 +5132,7 @@ var ZenFSConfig = (() => {
|
|
|
4979
5132
|
const tx = __addDisposableResource(env_20, this.transaction(), false);
|
|
4980
5133
|
if (tx.getSync(rootIno))
|
|
4981
5134
|
return;
|
|
4982
|
-
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 |
|
|
5135
|
+
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 | S_IFDIR2 });
|
|
4983
5136
|
tx.setSync(inode.data, encodeUTF8("{}"));
|
|
4984
5137
|
this._add(rootIno, "/");
|
|
4985
5138
|
tx.setSync(rootIno, inode);
|
|
@@ -5006,7 +5159,7 @@ var ZenFSConfig = (() => {
|
|
|
5006
5159
|
const rootData = await tx.get(rootIno);
|
|
5007
5160
|
if (!rootData) {
|
|
5008
5161
|
notice("Store does not have a root inode");
|
|
5009
|
-
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 |
|
|
5162
|
+
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 | S_IFDIR2 });
|
|
5010
5163
|
await tx.set(inode.data, encodeUTF8("{}"));
|
|
5011
5164
|
this._add(rootIno, "/");
|
|
5012
5165
|
await tx.set(rootIno, inode);
|
|
@@ -5034,7 +5187,7 @@ var ZenFSConfig = (() => {
|
|
|
5034
5187
|
continue;
|
|
5035
5188
|
}
|
|
5036
5189
|
const inode = new Inode(inodeData);
|
|
5037
|
-
if ((inode.mode &
|
|
5190
|
+
if ((inode.mode & S_IFDIR2) != S_IFDIR2 || visitedDirectories.has(ino)) {
|
|
5038
5191
|
continue;
|
|
5039
5192
|
}
|
|
5040
5193
|
visitedDirectories.add(ino);
|
|
@@ -5070,7 +5223,7 @@ var ZenFSConfig = (() => {
|
|
|
5070
5223
|
const rootData = tx.getSync(rootIno);
|
|
5071
5224
|
if (!rootData) {
|
|
5072
5225
|
notice("Store does not have a root inode");
|
|
5073
|
-
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 |
|
|
5226
|
+
const inode = new Inode({ ino: rootIno, data: 1, mode: 511 | S_IFDIR2 });
|
|
5074
5227
|
tx.setSync(inode.data, encodeUTF8("{}"));
|
|
5075
5228
|
this._add(rootIno, "/");
|
|
5076
5229
|
tx.setSync(rootIno, inode);
|
|
@@ -5098,7 +5251,7 @@ var ZenFSConfig = (() => {
|
|
|
5098
5251
|
continue;
|
|
5099
5252
|
}
|
|
5100
5253
|
const inode = new Inode(inodeData);
|
|
5101
|
-
if ((inode.mode &
|
|
5254
|
+
if ((inode.mode & S_IFDIR2) != S_IFDIR2 || visitedDirectories.has(ino)) {
|
|
5102
5255
|
continue;
|
|
5103
5256
|
}
|
|
5104
5257
|
visitedDirectories.add(ino);
|
|
@@ -8504,8 +8657,8 @@ var ZenFSConfig = (() => {
|
|
|
8504
8657
|
throw UV("EBADF", "chmod", this.path);
|
|
8505
8658
|
const _ = __addDisposableResource3(env_5, this.vnode.lockSync("rw"), false);
|
|
8506
8659
|
this.vnode.metadataDirty = true;
|
|
8507
|
-
this.inode.mode = this.inode.mode & (mode >
|
|
8508
|
-
if (this._isSync || mode >
|
|
8660
|
+
this.inode.mode = this.inode.mode & (mode > S_IFMT2 ? ~S_IFMT2 : S_IFMT2) | mode;
|
|
8661
|
+
if (this._isSync || mode > S_IFMT2)
|
|
8509
8662
|
this.vnode.syncSync();
|
|
8510
8663
|
} catch (e_5) {
|
|
8511
8664
|
env_5.error = e_5;
|
|
@@ -8702,8 +8855,8 @@ var ZenFSConfig = (() => {
|
|
|
8702
8855
|
throw UV("EBADF", "chmod", this.path);
|
|
8703
8856
|
const _ = __addDisposableResource3(env_12, await this.vnode.lock("rw"), false);
|
|
8704
8857
|
this.vnode.metadataDirty = true;
|
|
8705
|
-
this.inode.mode = this.inode.mode & (mode >
|
|
8706
|
-
if (this._isSync || mode >
|
|
8858
|
+
this.inode.mode = this.inode.mode & (mode > S_IFMT2 ? ~S_IFMT2 : S_IFMT2) | mode;
|
|
8859
|
+
if (this._isSync || mode > S_IFMT2)
|
|
8707
8860
|
await this.vnode.sync();
|
|
8708
8861
|
} catch (e_12) {
|
|
8709
8862
|
env_12.error = e_12;
|
|
@@ -9114,7 +9267,7 @@ var ZenFSConfig = (() => {
|
|
|
9114
9267
|
if (!isDirectory2(parentStats)) {
|
|
9115
9268
|
throw UV("ENOTDIR", "open", path);
|
|
9116
9269
|
}
|
|
9117
|
-
if (!opt.allowDirectory && mode &
|
|
9270
|
+
if (!opt.allowDirectory && mode & S_IFDIR2)
|
|
9118
9271
|
throw UV("EISDIR", "open", path);
|
|
9119
9272
|
const _ = __addDisposableResource4(env_1, lockPathSync(fs, parentPath, "rw", parentStats), false);
|
|
9120
9273
|
const { euid: uid, egid: gid } = contextOf(this).credentials;
|
|
@@ -9137,7 +9290,7 @@ var ZenFSConfig = (() => {
|
|
|
9137
9290
|
}
|
|
9138
9291
|
if (flag & O_EXCL)
|
|
9139
9292
|
throw UV("EEXIST", "open", path);
|
|
9140
|
-
if (!opt.allowDirectory && stats.mode &
|
|
9293
|
+
if (!opt.allowDirectory && stats.mode & S_IFDIR2)
|
|
9141
9294
|
throw UV("EISDIR", "open", path);
|
|
9142
9295
|
const file = new Handle(this, path, resolved, flag, cacheOf(fs).ref(resolved, stats));
|
|
9143
9296
|
if (flag & O_TRUNC)
|
|
@@ -9953,8 +10106,8 @@ var ZenFSConfig = (() => {
|
|
|
9953
10106
|
}
|
|
9954
10107
|
if (!stats)
|
|
9955
10108
|
return;
|
|
9956
|
-
switch (stats.mode &
|
|
9957
|
-
case
|
|
10109
|
+
switch (stats.mode & S_IFMT2) {
|
|
10110
|
+
case S_IFDIR2:
|
|
9958
10111
|
if (options?.recursive) {
|
|
9959
10112
|
for (const entry of readdirSync.call(this, path)) {
|
|
9960
10113
|
rmSync.call(this, join(path, entry), options);
|
|
@@ -10020,8 +10173,8 @@ var ZenFSConfig = (() => {
|
|
|
10020
10173
|
const srcStats = lstatSync.call(this, source);
|
|
10021
10174
|
if (opts?.errorOnExist && existsSync.call(this, destination))
|
|
10022
10175
|
throw UV("EEXIST", "cp", destination);
|
|
10023
|
-
switch (srcStats.mode &
|
|
10024
|
-
case
|
|
10176
|
+
switch (srcStats.mode & S_IFMT2) {
|
|
10177
|
+
case S_IFDIR2:
|
|
10025
10178
|
if (!opts?.recursive)
|
|
10026
10179
|
throw UV("EISDIR", "cp", source);
|
|
10027
10180
|
mkdirSync.call(this, destination, { recursive: true });
|
|
@@ -10373,7 +10526,7 @@ var ZenFSConfig = (() => {
|
|
|
10373
10526
|
throw UV("EACCES", "open", dirname(path));
|
|
10374
10527
|
if (!isDirectory2(parentStats))
|
|
10375
10528
|
throw UV("ENOTDIR", "open", dirname(path));
|
|
10376
|
-
if (!opt.allowDirectory && mode &
|
|
10529
|
+
if (!opt.allowDirectory && mode & S_IFDIR2)
|
|
10377
10530
|
throw UV("EISDIR", "open", path);
|
|
10378
10531
|
const _ = __addDisposableResource6(env_1, await lockPath(fs, parentPath, "rw", parentStats), false);
|
|
10379
10532
|
stats = cacheOf(fs).get(resolved)?.inode ?? await fs.stat(resolved).catch(() => void 0);
|
|
@@ -10398,7 +10551,7 @@ var ZenFSConfig = (() => {
|
|
|
10398
10551
|
throw UV("EACCES", $ex);
|
|
10399
10552
|
if (flag & O_EXCL)
|
|
10400
10553
|
throw UV("EEXIST", $ex);
|
|
10401
|
-
if (!opt.allowDirectory && mode &
|
|
10554
|
+
if (!opt.allowDirectory && mode & S_IFDIR2)
|
|
10402
10555
|
throw UV("EISDIR", "open", path);
|
|
10403
10556
|
const handle = new Handle($, path, resolved, flag, cacheOf(fs).ref(resolved, stats));
|
|
10404
10557
|
if (flag & O_TRUNC)
|
|
@@ -17963,8 +18116,8 @@ var ZenFSConfig = (() => {
|
|
|
17963
18116
|
});
|
|
17964
18117
|
if (!stats)
|
|
17965
18118
|
return;
|
|
17966
|
-
switch (stats.mode &
|
|
17967
|
-
case
|
|
18119
|
+
switch (stats.mode & S_IFMT2) {
|
|
18120
|
+
case S_IFDIR2:
|
|
17968
18121
|
if (options?.recursive) {
|
|
17969
18122
|
for (const entry of await readdir2.call(this, path)) {
|
|
17970
18123
|
await rm.call(this, join(path, entry), options);
|
|
@@ -18014,8 +18167,8 @@ var ZenFSConfig = (() => {
|
|
|
18014
18167
|
const srcStats = await lstat.call(this, source);
|
|
18015
18168
|
if (opts?.errorOnExist && await exists.call(this, destination))
|
|
18016
18169
|
throw UV("EEXIST", "cp", destination);
|
|
18017
|
-
switch (srcStats.mode &
|
|
18018
|
-
case
|
|
18170
|
+
switch (srcStats.mode & S_IFMT2) {
|
|
18171
|
+
case S_IFDIR2: {
|
|
18019
18172
|
if (!opts?.recursive)
|
|
18020
18173
|
throw UV("EISDIR", "cp", source);
|
|
18021
18174
|
const [entries2] = await Promise.all(
|
|
@@ -19445,7 +19598,7 @@ var ZenFSConfig = (() => {
|
|
|
19445
19598
|
for (const { to, inode } of toRename) {
|
|
19446
19599
|
const data = contents.get(to);
|
|
19447
19600
|
this.index.set(to, inode);
|
|
19448
|
-
if ((inode.mode &
|
|
19601
|
+
if ((inode.mode & S_IFMT2) == S_IFDIR2)
|
|
19449
19602
|
await this._mkdir?.(to, inode);
|
|
19450
19603
|
else
|
|
19451
19604
|
await this.write(to, data, 0);
|
|
@@ -19469,7 +19622,7 @@ var ZenFSConfig = (() => {
|
|
|
19469
19622
|
for (const { to, inode } of toRename) {
|
|
19470
19623
|
const data = contents.get(to);
|
|
19471
19624
|
this.index.set(to, inode);
|
|
19472
|
-
if ((inode.mode &
|
|
19625
|
+
if ((inode.mode & S_IFMT2) == S_IFDIR2)
|
|
19473
19626
|
this._mkdirSync?.(to, inode);
|
|
19474
19627
|
else
|
|
19475
19628
|
this.writeSync(to, data, 0);
|
|
@@ -19499,7 +19652,7 @@ var ZenFSConfig = (() => {
|
|
|
19499
19652
|
const inode = this.index.get(path);
|
|
19500
19653
|
if (!inode)
|
|
19501
19654
|
throw withErrno("ENOENT");
|
|
19502
|
-
const isDir2 = (inode.mode &
|
|
19655
|
+
const isDir2 = (inode.mode & S_IFMT2) == S_IFDIR2;
|
|
19503
19656
|
if (!isDir2 && !isUnlink)
|
|
19504
19657
|
throw withErrno("ENOTDIR");
|
|
19505
19658
|
if (isDir2 && isUnlink)
|
|
@@ -19556,13 +19709,13 @@ var ZenFSConfig = (() => {
|
|
|
19556
19709
|
return this.create(path, { ...options, mode: options.mode | S_IFREG });
|
|
19557
19710
|
}
|
|
19558
19711
|
async mkdir(path, options) {
|
|
19559
|
-
options = { ...options, mode: options.mode |
|
|
19712
|
+
options = { ...options, mode: options.mode | S_IFDIR2 };
|
|
19560
19713
|
const inode = this.create(path, options);
|
|
19561
19714
|
await this._mkdir?.(path, options);
|
|
19562
19715
|
return inode;
|
|
19563
19716
|
}
|
|
19564
19717
|
mkdirSync(path, options) {
|
|
19565
|
-
options = { ...options, mode: options.mode |
|
|
19718
|
+
options = { ...options, mode: options.mode | S_IFDIR2 };
|
|
19566
19719
|
const inode = this.create(path, options);
|
|
19567
19720
|
this._mkdirSync?.(path, options);
|
|
19568
19721
|
return inode;
|
|
@@ -20048,7 +20201,7 @@ var ZenFSConfig = (() => {
|
|
|
20048
20201
|
handleResponse: () => handleResponse,
|
|
20049
20202
|
isMessage: () => isMessage,
|
|
20050
20203
|
isPort: () => isPort,
|
|
20051
|
-
request: () =>
|
|
20204
|
+
request: () => request2
|
|
20052
20205
|
});
|
|
20053
20206
|
function isPort(port) {
|
|
20054
20207
|
return port != null && typeof port == "object" && "channel" in port && "send" in port && "addHandler" in port && "removeHandler" in port;
|
|
@@ -20147,7 +20300,7 @@ var ZenFSConfig = (() => {
|
|
|
20147
20300
|
}
|
|
20148
20301
|
executors.delete(id);
|
|
20149
20302
|
}
|
|
20150
|
-
function
|
|
20303
|
+
function request2(request3, { port, timeout: ms = 1e3, fs }) {
|
|
20151
20304
|
const stack = "\n" + new Error().stack.slice("Error:".length);
|
|
20152
20305
|
if (!port)
|
|
20153
20306
|
throw err(withErrno("EINVAL", "Can not make an RPC request without a port"));
|
|
@@ -20161,7 +20314,7 @@ var ZenFSConfig = (() => {
|
|
|
20161
20314
|
}, ms);
|
|
20162
20315
|
const executor = { resolve: resolve4, reject, promise, fs, timeout };
|
|
20163
20316
|
executors.set(id, executor);
|
|
20164
|
-
port.send({ ...
|
|
20317
|
+
port.send({ ...request3, _zenfs: true, id, stack });
|
|
20165
20318
|
return promise;
|
|
20166
20319
|
}
|
|
20167
20320
|
function __requestMethod(req) {
|
|
@@ -20208,21 +20361,21 @@ var ZenFSConfig = (() => {
|
|
|
20208
20361
|
return async function(fs) {
|
|
20209
20362
|
detach(port, handler);
|
|
20210
20363
|
for (const event of events) {
|
|
20211
|
-
const
|
|
20212
|
-
await handleRequest(port, fs,
|
|
20364
|
+
const request3 = "data" in event ? event.data : event;
|
|
20365
|
+
await handleRequest(port, fs, request3);
|
|
20213
20366
|
}
|
|
20214
20367
|
};
|
|
20215
20368
|
}
|
|
20216
|
-
async function handleRequest(port, fs,
|
|
20217
|
-
if (!isMessage(
|
|
20369
|
+
async function handleRequest(port, fs, request3) {
|
|
20370
|
+
if (!isMessage(request3))
|
|
20218
20371
|
return;
|
|
20219
20372
|
let value, error;
|
|
20220
20373
|
const transferList = [];
|
|
20221
20374
|
try {
|
|
20222
|
-
switch (
|
|
20375
|
+
switch (request3.method) {
|
|
20223
20376
|
case "read": {
|
|
20224
|
-
__requestMethod(
|
|
20225
|
-
const [path, buffer, start, end] =
|
|
20377
|
+
__requestMethod(request3);
|
|
20378
|
+
const [path, buffer, start, end] = request3.args;
|
|
20226
20379
|
await fs.read(path, buffer, start, end);
|
|
20227
20380
|
value = buffer;
|
|
20228
20381
|
break;
|
|
@@ -20230,26 +20383,26 @@ var ZenFSConfig = (() => {
|
|
|
20230
20383
|
case "stat":
|
|
20231
20384
|
case "createFile":
|
|
20232
20385
|
case "mkdir": {
|
|
20233
|
-
__requestMethod(
|
|
20234
|
-
const md = await fs[
|
|
20386
|
+
__requestMethod(request3);
|
|
20387
|
+
const md = await fs[request3.method](...request3.args);
|
|
20235
20388
|
const inode = md instanceof Inode ? md : new Inode(md);
|
|
20236
20389
|
value = new Uint8Array(inode.buffer, inode.byteOffset, inode.byteLength);
|
|
20237
20390
|
break;
|
|
20238
20391
|
}
|
|
20239
20392
|
case "touch": {
|
|
20240
|
-
__requestMethod(
|
|
20241
|
-
const [path, metadata] =
|
|
20393
|
+
__requestMethod(request3);
|
|
20394
|
+
const [path, metadata] = request3.args;
|
|
20242
20395
|
await fs.touch(path, new Inode(metadata));
|
|
20243
20396
|
value = void 0;
|
|
20244
20397
|
break;
|
|
20245
20398
|
}
|
|
20246
20399
|
default:
|
|
20247
|
-
value = await fs[
|
|
20400
|
+
value = await fs[request3.method](...request3.args);
|
|
20248
20401
|
}
|
|
20249
20402
|
} catch (e) {
|
|
20250
20403
|
error = e instanceof Exception ? e.toJSON() : pick(e, "message", "stack");
|
|
20251
20404
|
}
|
|
20252
|
-
port.send({ _zenfs: true, ...pick(
|
|
20405
|
+
port.send({ _zenfs: true, ...pick(request3, "id", "method", "stack"), error, value }, transferList);
|
|
20253
20406
|
}
|
|
20254
20407
|
var encodingVersion, executors;
|
|
20255
20408
|
var init_rpc = __esm({
|
|
@@ -20516,11 +20669,11 @@ var ZenFSConfig = (() => {
|
|
|
20516
20669
|
// node_modules/@zenfs/core/dist/backends/port.js
|
|
20517
20670
|
function attachFS(channel, fs) {
|
|
20518
20671
|
const port = from(channel);
|
|
20519
|
-
attach(port, (
|
|
20672
|
+
attach(port, (request3) => handleRequest(port, fs, request3));
|
|
20520
20673
|
}
|
|
20521
20674
|
function detachFS(channel, fs) {
|
|
20522
20675
|
const port = from(channel);
|
|
20523
|
-
detach(port, (
|
|
20676
|
+
detach(port, (request3) => handleRequest(port, fs, request3));
|
|
20524
20677
|
}
|
|
20525
20678
|
async function resolveRemoteMount(channel, config, _depth = 0) {
|
|
20526
20679
|
const port = from(channel);
|
|
@@ -20562,7 +20715,7 @@ var ZenFSConfig = (() => {
|
|
|
20562
20715
|
attach(this.port, handleResponse);
|
|
20563
20716
|
}
|
|
20564
20717
|
rpc(method, ...args) {
|
|
20565
|
-
return
|
|
20718
|
+
return request2({ method, args }, {
|
|
20566
20719
|
port: this.port,
|
|
20567
20720
|
timeout: this.timeout,
|
|
20568
20721
|
fs: this
|
|
@@ -23898,12 +24051,12 @@ var ZenFSConfig = (() => {
|
|
|
23898
24051
|
});
|
|
23899
24052
|
|
|
23900
24053
|
// node_modules/@zenfs/dom/dist/IndexedDB.js
|
|
23901
|
-
function wrap2(
|
|
24054
|
+
function wrap2(request3) {
|
|
23902
24055
|
return new Promise((resolve4, reject) => {
|
|
23903
|
-
|
|
23904
|
-
|
|
24056
|
+
request3.onsuccess = () => resolve4(request3.result);
|
|
24057
|
+
request3.onerror = (e) => {
|
|
23905
24058
|
e.preventDefault();
|
|
23906
|
-
reject(convertException(
|
|
24059
|
+
reject(convertException(request3.error));
|
|
23907
24060
|
};
|
|
23908
24061
|
});
|
|
23909
24062
|
}
|
|
@@ -24580,6 +24733,7 @@ var ZenFSConfig = (() => {
|
|
|
24580
24733
|
var init_backend_registry = __esm({
|
|
24581
24734
|
"src/backend-registry.ts"() {
|
|
24582
24735
|
"use strict";
|
|
24736
|
+
init_idb_repair();
|
|
24583
24737
|
registry = /* @__PURE__ */ new Map();
|
|
24584
24738
|
metadataRegistry = /* @__PURE__ */ new Map();
|
|
24585
24739
|
inMemoryCounter = 0;
|
|
@@ -24604,6 +24758,12 @@ var ZenFSConfig = (() => {
|
|
|
24604
24758
|
const { IndexedDB: IndexedDB2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports2));
|
|
24605
24759
|
const storeName = options.storeName ?? "zen-fs-config";
|
|
24606
24760
|
const label = options.label ?? storeName;
|
|
24761
|
+
const repaired = await repairIndexedDBStore(storeName);
|
|
24762
|
+
if (repaired?.repaired) {
|
|
24763
|
+
console.warn(
|
|
24764
|
+
`[Backend:IndexedDB] ${storeName}: reset ${repaired.repaired} corrupted directory listing(s): ` + repaired.details.map((d) => `ino ${d.key}\u2192slot ${d.data} (${d.reason})`).join(", ")
|
|
24765
|
+
);
|
|
24766
|
+
}
|
|
24607
24767
|
return wrapZenFSFileSystem({ backend: IndexedDB2, storeName, label });
|
|
24608
24768
|
}, {
|
|
24609
24769
|
type: "IndexedDB",
|
|
@@ -27125,8 +27285,8 @@ var ZenFSConfig = (() => {
|
|
|
27125
27285
|
}
|
|
27126
27286
|
function deleteDataGroupLocalStore(appId, groupId, options = {}) {
|
|
27127
27287
|
const storeName = dataGroupLocalStoreName(appId, groupId);
|
|
27128
|
-
const
|
|
27129
|
-
if (!
|
|
27288
|
+
const idb2 = globalThis.indexedDB;
|
|
27289
|
+
if (!idb2 || typeof idb2.deleteDatabase !== "function") {
|
|
27130
27290
|
return Promise.resolve({
|
|
27131
27291
|
storeName,
|
|
27132
27292
|
deleted: false,
|
|
@@ -27146,21 +27306,21 @@ var ZenFSConfig = (() => {
|
|
|
27146
27306
|
if (timer) clearTimeout(timer);
|
|
27147
27307
|
resolve4(result);
|
|
27148
27308
|
};
|
|
27149
|
-
let
|
|
27309
|
+
let request3;
|
|
27150
27310
|
try {
|
|
27151
|
-
|
|
27311
|
+
request3 = idb2.deleteDatabase(storeName);
|
|
27152
27312
|
} catch (err2) {
|
|
27153
27313
|
finish({ storeName, deleted: false, blocked: false, error: summarizeError(err2).message });
|
|
27154
27314
|
return;
|
|
27155
27315
|
}
|
|
27156
|
-
|
|
27157
|
-
|
|
27316
|
+
request3.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
|
|
27317
|
+
request3.onerror = () => finish({
|
|
27158
27318
|
storeName,
|
|
27159
27319
|
deleted: false,
|
|
27160
27320
|
blocked: false,
|
|
27161
|
-
error: summarizeError(
|
|
27321
|
+
error: summarizeError(request3.error).message
|
|
27162
27322
|
});
|
|
27163
|
-
|
|
27323
|
+
request3.onblocked = () => {
|
|
27164
27324
|
blocked = true;
|
|
27165
27325
|
};
|
|
27166
27326
|
timer = setTimeout(() => {
|
|
@@ -28246,9 +28406,9 @@ var ZenFSConfig = (() => {
|
|
|
28246
28406
|
function isMtimeSidecar(fileName) {
|
|
28247
28407
|
return fileName.endsWith(".mtime");
|
|
28248
28408
|
}
|
|
28249
|
-
var
|
|
28409
|
+
var S_IFDIR3 = 16384;
|
|
28250
28410
|
function isDirectory3(stat5) {
|
|
28251
|
-
return typeof stat5.mode === "number" && (stat5.mode &
|
|
28411
|
+
return typeof stat5.mode === "number" && (stat5.mode & S_IFDIR3) === S_IFDIR3;
|
|
28252
28412
|
}
|
|
28253
28413
|
function joinPath(dir, entry) {
|
|
28254
28414
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -28300,10 +28460,10 @@ var ZenFSConfig = (() => {
|
|
|
28300
28460
|
function isKeepFile(fileName) {
|
|
28301
28461
|
return fileName === ".keep";
|
|
28302
28462
|
}
|
|
28303
|
-
var
|
|
28463
|
+
var S_IFDIR4 = 16384;
|
|
28304
28464
|
var DEFAULT_PROTECTED_DIRS = ["/.meta/backends/.keep"];
|
|
28305
28465
|
function isDirectory4(stat5) {
|
|
28306
|
-
return typeof stat5.mode === "number" && (stat5.mode &
|
|
28466
|
+
return typeof stat5.mode === "number" && (stat5.mode & S_IFDIR4) === S_IFDIR4;
|
|
28307
28467
|
}
|
|
28308
28468
|
function joinPath2(dir, entry) {
|
|
28309
28469
|
if (dir === "/" || dir === "") return `/${entry}`;
|
|
@@ -28361,9 +28521,9 @@ var ZenFSConfig = (() => {
|
|
|
28361
28521
|
}
|
|
28362
28522
|
|
|
28363
28523
|
// src/version-migration.ts
|
|
28364
|
-
var
|
|
28524
|
+
var S_IFDIR5 = 16384;
|
|
28365
28525
|
function isDir(stat5) {
|
|
28366
|
-
return typeof stat5.mode === "number" && (stat5.mode &
|
|
28526
|
+
return typeof stat5.mode === "number" && (stat5.mode & S_IFDIR5) === S_IFDIR5;
|
|
28367
28527
|
}
|
|
28368
28528
|
function joinPath3(dir, entry) {
|
|
28369
28529
|
if (dir === "/" || dir === "") return `/${entry}`;
|