braidfs 0.0.130 → 0.0.131
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 +52 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -186,6 +186,9 @@ async function main() {
|
|
|
186
186
|
var version = [sync.peer + "-" + (sync.local_edit_counter - 1)]
|
|
187
187
|
await braid_text.put(sync.url, { version, parents, patches, merge_type: 'dt' })
|
|
188
188
|
|
|
189
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
190
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()}:${sync.url} -- plugin edited (${sync.investigating_disconnects_thinks_connected})\n`)
|
|
191
|
+
|
|
189
192
|
// may be able to do this more efficiently.. we want to make sure we're capturing a file write that is after our version was written.. there may be a way we can avoid calling file_needs_writing here
|
|
190
193
|
await new Promise(done => {
|
|
191
194
|
sync.file_written_cbs.push(done)
|
|
@@ -460,6 +463,41 @@ async function sync_url(url) {
|
|
|
460
463
|
}
|
|
461
464
|
sync_url.cache[path] = sync_url.chain = sync_url.chain.then(init)
|
|
462
465
|
}
|
|
466
|
+
|
|
467
|
+
async function detect_merge_type() {
|
|
468
|
+
// special case for .braidfs/config and .braidfs/error
|
|
469
|
+
if (url.startsWith('.braidfs/')) return 'dt'
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
var meta = JSON.parse(await require('fs').promises.readFile(meta_path, 'utf8'))
|
|
473
|
+
|
|
474
|
+
// optimization for old braidfs versions
|
|
475
|
+
if (typeof meta.local_edit_counter === 'number') return 'dt'
|
|
476
|
+
|
|
477
|
+
if (meta.merge_type) return meta.merge_type
|
|
478
|
+
} catch (e) {}
|
|
479
|
+
if (freed) return
|
|
480
|
+
|
|
481
|
+
var res = await braid_fetch(url, {
|
|
482
|
+
method: 'HEAD',
|
|
483
|
+
retry: () => true,
|
|
484
|
+
// braid_fetch will await this function on each reconnect when retrying
|
|
485
|
+
parents: async () => reconnect_rate_limiter.get_turn(url),
|
|
486
|
+
// version needed to force Merge-Type return header
|
|
487
|
+
version: [],
|
|
488
|
+
headers: {
|
|
489
|
+
// needed for braid.org routing
|
|
490
|
+
Accept: 'text/plain',
|
|
491
|
+
// in case it supports dt, so it doesn't give us "simpleton"
|
|
492
|
+
'Merge-Type': 'dt',
|
|
493
|
+
}
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
var merge_type = res.headers.get('merge-type')
|
|
497
|
+
if (merge_type) return merge_type
|
|
498
|
+
|
|
499
|
+
throw `failed to get merge type for ${url}`
|
|
500
|
+
}
|
|
463
501
|
|
|
464
502
|
async function init_binary_sync() {
|
|
465
503
|
if (freed) return
|
|
@@ -738,6 +776,9 @@ async function sync_url(url) {
|
|
|
738
776
|
// hack: remvoe in future
|
|
739
777
|
var old_meta_fork_point = null
|
|
740
778
|
|
|
779
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
780
|
+
self.investigating_disconnects_thinks_connected = false
|
|
781
|
+
|
|
741
782
|
// store a recent mapping of content-hashes to their versions,
|
|
742
783
|
// to support the command line: braidfs editing filename < file
|
|
743
784
|
self.hash_to_version_cache = new Map()
|
|
@@ -799,8 +840,12 @@ async function sync_url(url) {
|
|
|
799
840
|
!({
|
|
800
841
|
version: file_last_version,
|
|
801
842
|
digest: file_last_digest,
|
|
802
|
-
|
|
803
|
-
|
|
843
|
+
|
|
844
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
845
|
+
// create new peer to eliminate this as a potential issue for now:
|
|
846
|
+
// peer: self.peer,
|
|
847
|
+
// local_edit_counter: self.local_edit_counter,
|
|
848
|
+
|
|
804
849
|
fork_point: old_meta_fork_point
|
|
805
850
|
} = Array.isArray(meta) ? { version: meta } : meta)
|
|
806
851
|
|
|
@@ -912,6 +957,9 @@ async function sync_url(url) {
|
|
|
912
957
|
await wait_on(braid_text.put(url, { version, parents, patches, merge_type: 'dt' }))
|
|
913
958
|
if (freed) return
|
|
914
959
|
|
|
960
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
961
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()}:${url} -- file edited (${self.investigating_disconnects_thinks_connected})\n`)
|
|
962
|
+
|
|
915
963
|
await write_meta_file()
|
|
916
964
|
if (freed) return
|
|
917
965
|
} else {
|
|
@@ -1037,6 +1085,7 @@ async function sync_url(url) {
|
|
|
1037
1085
|
on_res: res => {
|
|
1038
1086
|
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1039
1087
|
do_investigating_disconnects_log(url, `sync.on_res status:${res?.status}`)
|
|
1088
|
+
self.investigating_disconnects_thinks_connected = res?.status
|
|
1040
1089
|
|
|
1041
1090
|
if (freed) return
|
|
1042
1091
|
reconnect_rate_limiter.on_conn(url)
|
|
@@ -1055,6 +1104,7 @@ async function sync_url(url) {
|
|
|
1055
1104
|
on_disconnect: () => {
|
|
1056
1105
|
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1057
1106
|
do_investigating_disconnects_log(url, `sync.on_disconnect`)
|
|
1107
|
+
self.investigating_disconnects_thinks_connected = false
|
|
1058
1108
|
|
|
1059
1109
|
return reconnect_rate_limiter.on_diss(url)
|
|
1060
1110
|
}
|