@componentor/fs 3.0.2 → 3.0.3
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/README.md +35 -16
- package/dist/index.js +226 -24
- package/dist/index.js.map +1 -1
- package/dist/workers/sync-relay.worker.js +64 -13
- package/dist/workers/sync-relay.worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -1324,6 +1324,7 @@ var leaderLoopRunning = false;
|
|
|
1324
1324
|
var opfsSyncPort = null;
|
|
1325
1325
|
var opfsSyncEnabled = false;
|
|
1326
1326
|
var suppressPaths = /* @__PURE__ */ new Set();
|
|
1327
|
+
var watchBc = null;
|
|
1327
1328
|
var sab;
|
|
1328
1329
|
var ctrl;
|
|
1329
1330
|
var readySab;
|
|
@@ -1450,21 +1451,21 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1450
1451
|
break;
|
|
1451
1452
|
case OP.WRITE:
|
|
1452
1453
|
result = engine.write(path, data ?? new Uint8Array(0), flags);
|
|
1453
|
-
if (
|
|
1454
|
+
if (result.status === 0) {
|
|
1454
1455
|
syncOp = op;
|
|
1455
1456
|
syncPath = path;
|
|
1456
1457
|
}
|
|
1457
1458
|
break;
|
|
1458
1459
|
case OP.APPEND:
|
|
1459
1460
|
result = engine.append(path, data ?? new Uint8Array(0));
|
|
1460
|
-
if (
|
|
1461
|
+
if (result.status === 0) {
|
|
1461
1462
|
syncOp = op;
|
|
1462
1463
|
syncPath = path;
|
|
1463
1464
|
}
|
|
1464
1465
|
break;
|
|
1465
1466
|
case OP.UNLINK:
|
|
1466
1467
|
result = engine.unlink(path);
|
|
1467
|
-
if (
|
|
1468
|
+
if (result.status === 0) {
|
|
1468
1469
|
syncOp = op;
|
|
1469
1470
|
syncPath = path;
|
|
1470
1471
|
}
|
|
@@ -1477,14 +1478,14 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1477
1478
|
break;
|
|
1478
1479
|
case OP.MKDIR:
|
|
1479
1480
|
result = engine.mkdir(path, flags);
|
|
1480
|
-
if (
|
|
1481
|
+
if (result.status === 0) {
|
|
1481
1482
|
syncOp = op;
|
|
1482
1483
|
syncPath = path;
|
|
1483
1484
|
}
|
|
1484
1485
|
break;
|
|
1485
1486
|
case OP.RMDIR:
|
|
1486
1487
|
result = engine.rmdir(path, flags);
|
|
1487
|
-
if (
|
|
1488
|
+
if (result.status === 0) {
|
|
1488
1489
|
syncOp = op;
|
|
1489
1490
|
syncPath = path;
|
|
1490
1491
|
}
|
|
@@ -1495,7 +1496,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1495
1496
|
case OP.RENAME: {
|
|
1496
1497
|
const newPath = data ? decodeSecondPath(data) : "";
|
|
1497
1498
|
result = engine.rename(path, newPath);
|
|
1498
|
-
if (
|
|
1499
|
+
if (result.status === 0) {
|
|
1499
1500
|
syncOp = op;
|
|
1500
1501
|
syncPath = path;
|
|
1501
1502
|
syncNewPath = newPath;
|
|
@@ -1508,7 +1509,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1508
1509
|
case OP.TRUNCATE: {
|
|
1509
1510
|
const len = data ? new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(0, true) : 0;
|
|
1510
1511
|
result = engine.truncate(path, len);
|
|
1511
|
-
if (
|
|
1512
|
+
if (result.status === 0) {
|
|
1512
1513
|
syncOp = op;
|
|
1513
1514
|
syncPath = path;
|
|
1514
1515
|
}
|
|
@@ -1517,7 +1518,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1517
1518
|
case OP.COPY: {
|
|
1518
1519
|
const destPath = data ? decodeSecondPath(data) : "";
|
|
1519
1520
|
result = engine.copy(path, destPath, flags);
|
|
1520
|
-
if (
|
|
1521
|
+
if (result.status === 0) {
|
|
1521
1522
|
syncOp = op;
|
|
1522
1523
|
syncPath = destPath;
|
|
1523
1524
|
}
|
|
@@ -1532,6 +1533,10 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1532
1533
|
case OP.CHMOD: {
|
|
1533
1534
|
const chmodMode = data ? new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(0, true) : 0;
|
|
1534
1535
|
result = engine.chmod(path, chmodMode);
|
|
1536
|
+
if (result.status === 0) {
|
|
1537
|
+
syncOp = op;
|
|
1538
|
+
syncPath = path;
|
|
1539
|
+
}
|
|
1535
1540
|
break;
|
|
1536
1541
|
}
|
|
1537
1542
|
case OP.CHOWN: {
|
|
@@ -1543,6 +1548,10 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1543
1548
|
const uid = dv.getUint32(0, true);
|
|
1544
1549
|
const gid = dv.getUint32(4, true);
|
|
1545
1550
|
result = engine.chown(path, uid, gid);
|
|
1551
|
+
if (result.status === 0) {
|
|
1552
|
+
syncOp = op;
|
|
1553
|
+
syncPath = path;
|
|
1554
|
+
}
|
|
1546
1555
|
break;
|
|
1547
1556
|
}
|
|
1548
1557
|
case OP.UTIMES: {
|
|
@@ -1554,12 +1563,16 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1554
1563
|
const atime = dv.getFloat64(0, true);
|
|
1555
1564
|
const mtime = dv.getFloat64(8, true);
|
|
1556
1565
|
result = engine.utimes(path, atime, mtime);
|
|
1566
|
+
if (result.status === 0) {
|
|
1567
|
+
syncOp = op;
|
|
1568
|
+
syncPath = path;
|
|
1569
|
+
}
|
|
1557
1570
|
break;
|
|
1558
1571
|
}
|
|
1559
1572
|
case OP.SYMLINK: {
|
|
1560
1573
|
const target = data ? new TextDecoder().decode(data) : "";
|
|
1561
1574
|
result = engine.symlink(target, path);
|
|
1562
|
-
if (
|
|
1575
|
+
if (result.status === 0) {
|
|
1563
1576
|
syncOp = op;
|
|
1564
1577
|
syncPath = path;
|
|
1565
1578
|
}
|
|
@@ -1571,7 +1584,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1571
1584
|
case OP.LINK: {
|
|
1572
1585
|
const newPath = data ? decodeSecondPath(data) : "";
|
|
1573
1586
|
result = engine.link(path, newPath);
|
|
1574
|
-
if (
|
|
1587
|
+
if (result.status === 0) {
|
|
1575
1588
|
syncOp = op;
|
|
1576
1589
|
syncPath = newPath;
|
|
1577
1590
|
}
|
|
@@ -1607,7 +1620,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1607
1620
|
const pos = dv.getInt32(4, true);
|
|
1608
1621
|
const writeData = data.subarray(8);
|
|
1609
1622
|
result = engine.fwrite(fd, writeData, pos === -1 ? null : pos);
|
|
1610
|
-
if (
|
|
1623
|
+
if (result.status === 0) {
|
|
1611
1624
|
syncOp = op;
|
|
1612
1625
|
syncPath = engine.getPathForFd(fd) ?? void 0;
|
|
1613
1626
|
}
|
|
@@ -1627,7 +1640,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1627
1640
|
const fd = dv.getUint32(0, true);
|
|
1628
1641
|
const len = dv.getUint32(4, true);
|
|
1629
1642
|
result = engine.ftruncate(fd, len);
|
|
1630
|
-
if (
|
|
1643
|
+
if (result.status === 0) {
|
|
1631
1644
|
syncOp = op;
|
|
1632
1645
|
syncPath = engine.getPathForFd(fd) ?? void 0;
|
|
1633
1646
|
}
|
|
@@ -1641,7 +1654,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1641
1654
|
break;
|
|
1642
1655
|
case OP.MKDTEMP:
|
|
1643
1656
|
result = engine.mkdtemp(path);
|
|
1644
|
-
if (
|
|
1657
|
+
if (result.status === 0 && result.data) {
|
|
1645
1658
|
syncOp = op;
|
|
1646
1659
|
syncPath = new TextDecoder().decode(result.data instanceof Uint8Array ? result.data : new Uint8Array(0));
|
|
1647
1660
|
}
|
|
@@ -1661,6 +1674,7 @@ function handleRequest(reqTabId, buffer) {
|
|
|
1661
1674
|
ret._op = syncOp;
|
|
1662
1675
|
ret._path = syncPath;
|
|
1663
1676
|
ret._newPath = syncNewPath;
|
|
1677
|
+
broadcastWatch(syncOp, syncPath, syncNewPath);
|
|
1664
1678
|
}
|
|
1665
1679
|
return ret;
|
|
1666
1680
|
}
|
|
@@ -1851,6 +1865,39 @@ async function initEngine(config) {
|
|
|
1851
1865
|
[mc.port2]
|
|
1852
1866
|
);
|
|
1853
1867
|
}
|
|
1868
|
+
watchBc = new BroadcastChannel("vfs-watch");
|
|
1869
|
+
}
|
|
1870
|
+
function broadcastWatch(op, path, newPath) {
|
|
1871
|
+
if (!watchBc) return;
|
|
1872
|
+
let eventType;
|
|
1873
|
+
switch (op) {
|
|
1874
|
+
case OP.WRITE:
|
|
1875
|
+
case OP.APPEND:
|
|
1876
|
+
case OP.TRUNCATE:
|
|
1877
|
+
case OP.FWRITE:
|
|
1878
|
+
case OP.FTRUNCATE:
|
|
1879
|
+
case OP.CHMOD:
|
|
1880
|
+
case OP.CHOWN:
|
|
1881
|
+
case OP.UTIMES:
|
|
1882
|
+
eventType = "change";
|
|
1883
|
+
break;
|
|
1884
|
+
case OP.UNLINK:
|
|
1885
|
+
case OP.RMDIR:
|
|
1886
|
+
case OP.RENAME:
|
|
1887
|
+
case OP.MKDIR:
|
|
1888
|
+
case OP.MKDTEMP:
|
|
1889
|
+
case OP.SYMLINK:
|
|
1890
|
+
case OP.LINK:
|
|
1891
|
+
case OP.COPY:
|
|
1892
|
+
eventType = "rename";
|
|
1893
|
+
break;
|
|
1894
|
+
default:
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
watchBc.postMessage({ eventType, path });
|
|
1898
|
+
if (op === OP.RENAME && newPath) {
|
|
1899
|
+
watchBc.postMessage({ eventType: "rename", path: newPath });
|
|
1900
|
+
}
|
|
1854
1901
|
}
|
|
1855
1902
|
function notifyOPFSSync(op, path, newPath) {
|
|
1856
1903
|
if (!opfsSyncPort) return;
|
|
@@ -1910,6 +1957,7 @@ function handleExternalChange(msg) {
|
|
|
1910
1957
|
case "external-write": {
|
|
1911
1958
|
suppressPaths.add(msg.path);
|
|
1912
1959
|
const result = engine.write(msg.path, new Uint8Array(msg.data), 0);
|
|
1960
|
+
if (result.status === 0) broadcastWatch(OP.WRITE, msg.path);
|
|
1913
1961
|
console.log("[sync-relay] external-write:", msg.path, `${msg.data?.byteLength ?? 0}B`, `status=${result.status}`);
|
|
1914
1962
|
break;
|
|
1915
1963
|
}
|
|
@@ -1918,8 +1966,10 @@ function handleExternalChange(msg) {
|
|
|
1918
1966
|
const result = engine.unlink(msg.path);
|
|
1919
1967
|
if (result.status !== 0) {
|
|
1920
1968
|
const rmdirResult = engine.rmdir(msg.path, 1);
|
|
1969
|
+
if (rmdirResult.status === 0) broadcastWatch(OP.RMDIR, msg.path);
|
|
1921
1970
|
console.log("[sync-relay] external-delete (rmdir):", msg.path, `status=${rmdirResult.status}`);
|
|
1922
1971
|
} else {
|
|
1972
|
+
broadcastWatch(OP.UNLINK, msg.path);
|
|
1923
1973
|
console.log("[sync-relay] external-delete:", msg.path, `status=${result.status}`);
|
|
1924
1974
|
}
|
|
1925
1975
|
break;
|
|
@@ -1929,6 +1979,7 @@ function handleExternalChange(msg) {
|
|
|
1929
1979
|
if (msg.newPath) {
|
|
1930
1980
|
suppressPaths.add(msg.newPath);
|
|
1931
1981
|
const result = engine.rename(msg.path, msg.newPath);
|
|
1982
|
+
if (result.status === 0) broadcastWatch(OP.RENAME, msg.path, msg.newPath);
|
|
1932
1983
|
console.log("[sync-relay] external-rename:", msg.path, "\u2192", msg.newPath, `status=${result.status}`);
|
|
1933
1984
|
}
|
|
1934
1985
|
break;
|