braidfs 0.0.131 → 0.0.132
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/index.js +23 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -429,6 +429,8 @@ async function sync_url(url) {
|
|
|
429
429
|
if (!sync_url.cache) sync_url.cache = {}
|
|
430
430
|
if (!sync_url.chain) sync_url.chain = Promise.resolve()
|
|
431
431
|
if (!sync_url.cache[path]) {
|
|
432
|
+
// console.log(`sync_url: ${url}`)
|
|
433
|
+
|
|
432
434
|
var self = {url},
|
|
433
435
|
freed = false,
|
|
434
436
|
aborts = new Set()
|
|
@@ -461,8 +463,17 @@ async function sync_url(url) {
|
|
|
461
463
|
await require('fs').promises.unlink(fp)
|
|
462
464
|
} catch (e) {}
|
|
463
465
|
}
|
|
464
|
-
|
|
466
|
+
|
|
467
|
+
sync_url.cache[path] = (async () => {
|
|
468
|
+
self.merge_type = await detect_merge_type()
|
|
469
|
+
if (self.merge_type === 'dt') {
|
|
470
|
+
return await (sync_url.chain = sync_url.chain.then(init))
|
|
471
|
+
} else if (self.merge_type === 'aww') {
|
|
472
|
+
return await (sync_url.chain = sync_url.chain.then(init_binary_sync))
|
|
473
|
+
} else throw new Error(`unknown merge-type: ${self.merge_type}`)
|
|
474
|
+
})()
|
|
465
475
|
}
|
|
476
|
+
return
|
|
466
477
|
|
|
467
478
|
async function detect_merge_type() {
|
|
468
479
|
// special case for .braidfs/config and .braidfs/error
|
|
@@ -500,12 +511,14 @@ async function sync_url(url) {
|
|
|
500
511
|
}
|
|
501
512
|
|
|
502
513
|
async function init_binary_sync() {
|
|
514
|
+
await ensure_path_stuff()
|
|
503
515
|
if (freed) return
|
|
504
516
|
|
|
505
517
|
console.log(`init_binary_sync: ${url}`)
|
|
506
518
|
|
|
507
519
|
async function save_meta() {
|
|
508
520
|
await require('fs').promises.writeFile(meta_path, JSON.stringify({
|
|
521
|
+
merge_type: self.merge_type,
|
|
509
522
|
peer: self.peer,
|
|
510
523
|
version: self.version,
|
|
511
524
|
file_mtimeNs_str: self.file_mtimeNs_str
|
|
@@ -735,12 +748,10 @@ async function sync_url(url) {
|
|
|
735
748
|
|
|
736
749
|
return self
|
|
737
750
|
}
|
|
738
|
-
|
|
739
|
-
async function init() {
|
|
740
|
-
if (freed) return
|
|
741
|
-
|
|
742
|
-
// console.log(`sync_url: ${url}`)
|
|
743
751
|
|
|
752
|
+
async function ensure_path_stuff() {
|
|
753
|
+
if (freed) return
|
|
754
|
+
|
|
744
755
|
// if we're accessing /blah/index, it will be normalized to /blah,
|
|
745
756
|
// but we still want to create a directory out of blah in this case
|
|
746
757
|
if (wasnt_normal && !(await is_dir(fullpath))) {
|
|
@@ -751,15 +762,11 @@ async function sync_url(url) {
|
|
|
751
762
|
|
|
752
763
|
await ensure_path(require("path").dirname(fullpath))
|
|
753
764
|
if (freed) return
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
// It notably does NOT handle `.braidfs/set_version/` and `.braidfs/get_version/` correctly!
|
|
760
|
-
// Search ` sync_url.cache[` to see how it's all handled.
|
|
761
|
-
return await init_binary_sync()
|
|
762
|
-
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
async function init() {
|
|
768
|
+
await ensure_path_stuff()
|
|
769
|
+
if (freed) return
|
|
763
770
|
|
|
764
771
|
self.peer = Math.random().toString(36).slice(2)
|
|
765
772
|
self.local_edit_counter = 0
|
|
@@ -903,6 +910,7 @@ async function sync_url(url) {
|
|
|
903
910
|
async function write_meta_file() {
|
|
904
911
|
if (freed) return
|
|
905
912
|
await wait_on(require('fs').promises.writeFile(meta_path, JSON.stringify({
|
|
913
|
+
merge_type: self.merge_type,
|
|
906
914
|
version: file_last_version,
|
|
907
915
|
digest: sha256(self.file_last_text),
|
|
908
916
|
peer: self.peer,
|
|
@@ -1123,7 +1131,6 @@ async function sync_url(url) {
|
|
|
1123
1131
|
start_sync()
|
|
1124
1132
|
return self
|
|
1125
1133
|
}
|
|
1126
|
-
return await sync_url.cache[url]
|
|
1127
1134
|
}
|
|
1128
1135
|
|
|
1129
1136
|
async function ensure_path(path) {
|