@secrez/fs 1.1.1 → 1.2.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/coverage.report CHANGED
@@ -1,203 +1,265 @@
1
1
 
2
- > @secrez/fs@1.0.7 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
2
+ > @secrez/fs@1.2.0 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
3
3
  > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
4
4
 
5
5
 
6
6
 
7
7
  #DataCache
8
- ✓ should initialize a dataCache
9
- ✓ should put and get data
10
- ✓ should load data from disk, if any
11
- ✓ should not load if no data
12
- ✓ should load plaintext data from disk, if any
13
- ✓ should load encrypted data from disk, if any
8
+ ✔ should initialize a dataCache
9
+ ✔ should put and get data
10
+ ✔ should load data from disk, if any
11
+ ✔ should not load if no data
12
+ ✔ should load plaintext data from disk, if any
13
+ ✔ should load encrypted data from disk, if any
14
14
 
15
15
  #ExternalFs
16
16
  getNormalizedPath
17
- ✓ should normalize "~/fileSystems"
18
- ✓ should normalize "~"
19
- ✓ should normalize "/var"
17
+ ✔ should normalize "~/fileSystems"
18
+ ✔ should normalize "~"
19
+ ✔ should normalize "/var"
20
20
  fileCompletion
21
- ✓ should return a list of files
22
- ✓ should return a list of only directories
23
- ✓ should return a list of only files
24
- ✓ should return the file itself, if it is not a directory
25
- ✓ should return the list of the files satisfying wildcards
26
- ✓ should return an empty list if the files does not exist
21
+ ✔ should return a list of files
22
+ ✔ should return a list of only directories
23
+ ✔ should return a list of only files
24
+ ✔ should return the file itself, if it is not a directory
25
+ ✔ should return the list of the files satisfying wildcards
26
+ ✔ should return an empty list if the files does not exist
27
27
  getVersionedBasename
28
- ✓ should version a file
28
+ ✔ should version a file
29
29
  isDir
30
- ✓ should confirm that "utils" is a dir
31
- ✓ should return that "config.test.js" is not a dir
32
- ✓ should return that a not-existent file is not a dir
30
+ ✔ should confirm that "utils" is a dir
31
+ ✔ should return that "config.test.js" is not a dir
32
+ ✔ should return that a not-existent file is not a dir
33
33
  isFile
34
- ✓ should return that "config.test.js" is a file
35
- ✓ should confirm that "utils" is not a file
36
- ✓ should return that a not-existent file is not a dir
34
+ ✔ should return that "config.test.js" is a file
35
+ ✔ should confirm that "utils" is not a file
36
+ ✔ should return that a not-existent file is not a dir
37
37
 
38
38
  #FileCipher
39
39
  encrypt/decrypt external file
40
- ✓ should encrypt a file using a specific password
41
- ✓ should encrypt a file using a shared key
42
- ✓ should encrypt a file using user's own public key
40
+ ✔ should encrypt a file using a specific password (v2)
41
+ ✔ should decrypt v1 password-encrypted files
42
+ ✔ should encrypt a file using a shared key
43
+ ✔ should encrypt a file using user's own public key
43
44
 
44
45
  #FsUtils
45
46
  preParseCommandLine
46
- ✓ should preParse a command line
47
- ✓ should preParse a command line with escaped pars
48
- ✓ should preParse a command line using quotes for params
47
+ ✔ should preParse a command line
48
+ ✔ should preParse a command line with escaped pars
49
+ ✔ should preParse a command line using quotes for params
49
50
  parseCommandLine
50
- ✓ should parse a command line with definitions
51
- ✓ should return a {} w/out definitions
52
- ✓ should return a {} w/out params
53
- ✓ should return an _unknown if not supported option is passed
51
+ ✔ should parse a command line with definitions
52
+ ✔ should return a {} w/out definitions
53
+ ✔ should return a {} w/out params
54
+ ✔ should return an _unknown if not supported option is passed
54
55
  filterLs
55
- ✓ should filter an array of files and return itself
56
- ✓ should filter an array of files starting from "te"
57
- ✓ should filter an array of files of type .log
58
- ✓ should filter an array of files and find the folders
59
- ✓ should get all the files
60
- ✓ should return an empty array if nothing is found
61
- ✓ should return an empty array if parameters are missed or empty
62
- ✓ should return all the list array if files are missed
56
+ ✔ should filter an array of files and return itself
57
+ ✔ should filter an array of files starting from "te"
58
+ ✔ should filter an array of files of type .log
59
+ ✔ should filter an array of files and find the folders
60
+ ✔ should get all the files
61
+ ✔ should return an empty array if nothing is found
62
+ ✔ should return an empty array if parameters are missed or empty
63
+ ✔ should return all the list array if files are missed
63
64
 
64
65
  #GitConflictChecker
65
- ✓ should detect non-git repository
66
- ✓ should return null status for non-git repository
67
- ✓ should not detect conflict risk in non-git repository
68
- with real GitHub repository
69
- ✓ should detect git repository
70
- ✓ should get git status when up to date with remote (3471ms)
71
- ✓ should detect conflict risk when behind remote (5794ms)
72
- ✓ should get warning message for conflict risk
73
- ✓ should not show alert again after user proceeds (3582ms)
74
- ✓ should reset cache
66
+ ✔ should detect non-git repository
67
+ ✔ should return null status for non-git repository
68
+ 1) should reuse a hard block without checking git again
69
+ 2) should reuse a behind-remote warning without checking git again
70
+ ✔ should fetch again after a push refreshes the fingerprint
71
+ ✔ should use the login fingerprint without fetching again
72
+ 3) should check git again when the risk can be bypassed
73
+ ✔ should not detect conflict risk in non-git repository
74
+ with local git repository
75
+ ✔ should detect git repository
76
+ ✔ should get git status when up to date with remote (156ms)
77
+ ✔ should detect conflict risk when behind remote (280ms)
78
+ ✔ should get warning message for conflict risk
79
+ ✔ should not show alert again after user proceeds (157ms)
80
+ ✔ should reset cache
75
81
 
76
82
  #InternalFs
77
83
  #constructor
78
- ✓ should instantiate the internal file system and initialize it
79
- ✓ should initialize the internal fs
80
- ✓ should throw if passing not a Secrez instance
84
+ ✔ should instantiate the internal file system and initialize it
85
+ ✔ should initialize the internal fs
86
+ ✔ should throw if passing not a Secrez instance
81
87
  getFullPath
82
- ✓ should return the fullPath of an entry
88
+ ✔ should return the fullPath of an entry
83
89
  normalizePath
84
- ✓ should normalize a path
85
- ✓ should throw if the path is empty, is not a string or is longer than 255 chars
90
+ ✔ should normalize a path
91
+ ✔ should throw if the path is empty, is not a string or is longer than 255 chars
86
92
  getNormalizedPath
87
- ✓ should normalize a path
93
+ ✔ should normalize a path
88
94
  make
89
- ✓ should create directories and files
90
- ✓ should throw trying to re-add the same entry
95
+ ✔ should create directories and files
96
+ ✔ should throw trying to re-add the same entry
91
97
  change
92
- ✓ should create directories and files and update them
93
- ✓ should return an error
94
- ✓ should move files between datasets
98
+ ✔ should create directories and files and update them
99
+ ✔ should return an error
100
+ ✔ should move files between datasets
95
101
  remove
96
- ✓ should remove a file from the tree
102
+ ✔ should remove a file from the tree
97
103
  load
98
- ✓ should create directories and files and loading a tree from disk
99
- ✓ should create directories and files, and load a tree from disk
100
- ✓ should create directories and files, delete everything and loading a tree from disk
101
- ✓ should compress and reload an empty set of entries
104
+ ✔ should create directories and files and loading a tree from disk
105
+ ✔ should create directories and files, and load a tree from disk
106
+ ✔ should create directories and files, delete everything and loading a tree from disk
107
+ ✔ should compress and reload an empty set of entries
102
108
  #getFileList
103
- ✓ should get the current folder dir
109
+ ✔ should get the current folder dir
104
110
 
105
111
  #Node
106
112
  #constructor
107
- ✓ should instantiate the Node
108
- ✓ should throw if passing a rot without required parameters
109
- ✓ should throw if not passing an object
110
- ✓ should throw if not passing wrong type
113
+ ✔ should instantiate the Node
114
+ ✔ should throw if passing a rot without required parameters
115
+ ✔ should throw if not passing an object
116
+ ✔ should throw if not passing wrong type
111
117
  #getName && #getFile && #getContent && getOptions
112
- ✓ should get name, file and options
113
- ✓ should throw if version not found
118
+ ✔ should get name, file and options
119
+ ✔ should throw if version not found
114
120
  #getFindRe
115
- ✓ should get a re to check a filepath
121
+ ✔ should get a re to check a filepath
116
122
  #getNames
117
- ✓ should get the names of all children
118
- ✓ should throw if trying to get children of a file
123
+ ✔ should get the names of all children
124
+ ✔ should throw if trying to get children of a file
119
125
  #find
120
- ✓ should find all childrens satisfying criterias
126
+ ✔ should find all childrens satisfying criterias
121
127
  #add
122
- ✓ should add children to root
123
- ✓ should throw if node is a file
128
+ ✔ should add children to root
129
+ ✔ should throw if node is a file
124
130
  #move
125
- ✓ should rename a node
126
- ✓ should move a node
127
- ✓ should throw trying to move root
128
- ✓ should throw trying to modify a node with different id
131
+ ✔ should rename a node
132
+ ✔ should move a node
133
+ ✔ should throw trying to move root
134
+ ✔ should throw trying to modify a node with different id
129
135
  #remove
130
- ✓ should remove a node
131
- ✓ should remove itself
132
- ✓ should throw trying to remove root
136
+ ✔ should remove a node
137
+ ✔ should remove itself
138
+ ✔ should throw trying to remove root
133
139
  #toCompressedJSON && Node#fromJSON
134
- ✓ should prepare a json for saving
135
- ✓ should build an index from a json file
140
+ ✔ should prepare a json for saving
141
+ ✔ should build an index from a json file
136
142
  #getChildFromPath
137
- ✓ should find a node starting from a path
138
- ✓ should find the last ancestor starting from a path
139
- ✓ should throw if the path is incorrect or does not exist
140
- ✓ should throw if looking for last ancestor and find existent node
143
+ ✔ should find a node starting from a path
144
+ ✔ should find the last ancestor starting from a path
145
+ ✔ should throw if the path is incorrect or does not exist
146
+ ✔ should throw if looking for last ancestor and find existent node
141
147
  #getPathToChild
142
- ✓ should find a node starting from a path
143
- ✓ should throw if child is not a Node
144
- ✓ should throw if child belows to another tree
148
+ ✔ should find a node starting from a path
149
+ ✔ should throw if child is not a Node
150
+ ✔ should throw if child belows to another tree
145
151
  #findDirectChildByName && #findChildById
146
- ✓ should find a direct child by name and by id
147
- ✓ should throw if looking for child of a file
148
- ✓ should throw if looking for child of a file
152
+ ✔ should find a direct child by name and by id
153
+ ✔ should throw if looking for child of a file
154
+ ✔ should throw if looking for child of a file
155
+
156
+ #recovery with three git clones
157
+ ✔ keeps the added file, drops the deleted one, and ends on one commit (2708ms)
149
158
 
150
159
  #Tree
151
160
  #constructor
152
- ✓ should instantiate the Tree
153
- ✓ should throw if passing not an Secrez instance
161
+ ✔ should instantiate the Tree
162
+ ✔ should throw if passing not an Secrez instance
154
163
  #load
155
- ✓ should load an empty Tree
156
- ✓ should do nothing if already loaded
164
+ ✔ should load an empty Tree
165
+ ✔ should do nothing if already loaded
157
166
  getEntryDetails
158
- ✓ should return the entry details of a node
167
+ ✔ should return the entry details of a node
159
168
  #Fix
160
- ✓ should load a tree with tags (52ms)
161
- 1) should simulate a conflict in the repo and recover lost entries when a valid tree exists
162
- ✓ should simulate a lost index in the repo and recover the entries when no valid tree is found (73ms)
169
+ ✔ should load a tree with tags
170
+ ✔ should simulate a conflict in the repo and recover lost entries when a valid tree exists (1101ms)
171
+ ✔ should not recover a deleted file when its blob is still on disk
172
+ ✔ should keep a recreated file when the deleted blob reappears
173
+ ✔ should simulate a lost index in the repo and recover the entries when no valid tree is found
163
174
  Multi data sets
164
- ✓ should load the trees of two data sets
175
+ ✔ should load the trees of two data sets
176
+
177
+
178
+ 113 passing (8s)
179
+ 3 failing
165
180
 
181
+ 1) #GitConflictChecker
182
+ should reuse a hard block without checking git again:
166
183
 
167
- 106 passing (44s)
168
- 1 failing
184
+ AssertionError: expected { hasRisk: true, …(4) } to equal { Object (hasRisk, riskType, ...) }
185
+ + expected - actual
186
+
187
+ {
188
+ - "allowBypass": false
189
+ - "hasRisk": true
190
+ - "message": "🚫 Repository State Changed Externally!\n \nThe git repository state has changed since you entered your account.\nThis likely means a 'git pull' or other git operation was performed in another terminal.\n\nSecrez cannot safely read these changes while running.\nFor data integrity, only READ operations and QUIT are allowed."
191
+ - "riskType": "external_change"
192
+ - "status": {
193
+ - "ahead": 0
194
+ - "behind": 0
195
+ - "headCommit": "abc"
196
+ - "localBranch": "main"
197
+ - "remoteBranch": "origin/main"
198
+ - "uncommitted": 0
199
+ - }
200
+ + "allowBypass": true
201
+ + "hasRisk": false
202
+ + "message": [null]
203
+ + "riskType": [null]
204
+ + "status": [null]
205
+ }
206
+
207
+ at Context.<anonymous> (test/GitConflictChecker.test.js:91:12)
208
+
209
+ 2) #GitConflictChecker
210
+ should reuse a behind-remote warning without checking git again:
211
+
212
+ AssertionError: expected { hasRisk: true, …(4) } to equal { Object (hasRisk, riskType, ...) }
213
+ + expected - actual
214
+
215
+ {
216
+ "allowBypass": true
217
+ - "hasRisk": true
218
+ - "message": "⚠️ Git Conflict Risk Detected!\n \nYour local repository is 1 commit(s) behind the remote 'origin/main' branch.\nAny changes you make now could lead to merge conflicts when you try to sync later."
219
+ - "riskType": "behind_remote"
220
+ - "status": {
221
+ - "ahead": 0
222
+ - "behind": 1
223
+ - "headCommit": "abc"
224
+ - "localBranch": "main"
225
+ - "remoteBranch": "origin/main"
226
+ - "uncommitted": 0
227
+ - }
228
+ + "hasRisk": false
229
+ + "message": [null]
230
+ + "riskType": [null]
231
+ + "status": [null]
232
+ }
233
+
234
+ at Context.<anonymous> (test/GitConflictChecker.test.js:117:12)
169
235
 
170
- 1) #Tree
171
- #Fix
172
- should simulate a conflict in the repo and recover lost entries when a valid tree exists:
236
+ 3) #GitConflictChecker
237
+ should check git again when the risk can be bypassed:
173
238
 
174
- AssertionError: expected [ '/B/D/g', '/B/b', '/E/L/N', …(1) ] to deeply equal [ '/B/D/g', '/B/b', '/E/L/N', '/E/c' ]
239
+ AssertionError: expected 1 to equal 2
175
240
  + expected - actual
176
241
 
177
- [
178
- "/B/D/g"
179
- "/B/b"
180
- "/E/L/N"
181
- - "/REC_20251009101127/d"
182
- + "/E/c"
183
- ]
242
+ -1
243
+ +2
184
244
 
185
- at Context.<anonymous> (test/Tree.test.js:306:14)
245
+ at Context.<anonymous> (test/GitConflictChecker.test.js:187:12)
186
246
 
187
247
 
188
248
 
189
249
  -----------------------|---------|----------|---------|---------|-----------------------------------
190
250
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
191
251
  -----------------------|---------|----------|---------|---------|-----------------------------------
192
- All files | 81.85 | 67.77 | 86.27 | 81.52 |
193
- DataCache.js | 89.41 | 74.07 | 90.9 | 89.28 | 17-23,122-123,149
252
+ All files | 83.88 | 71.81 | 88.02 | 83.61 |
253
+ DataCache.js | 89.53 | 74.07 | 90.9 | 89.41 | 18-24,123-124,150
194
254
  ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
195
- FileCipher.js | 88.63 | 73.33 | 100 | 88.63 | 8,52,80,85,94
255
+ FileCipher.js | 88.05 | 73.8 | 100 | 88.05 | 9,39,76,85,91,95,131,136
196
256
  FsUtils.js | 100 | 100 | 100 | 100 |
197
- GitConflictChecker.js | 72.81 | 61.9 | 90 | 72.81 | ...95,204,222,254,259,277,289,308
198
- InternalFs.js | 85.09 | 71.87 | 85.18 | 84.98 | ...33,344,364,423-428,460,470-487
257
+ GitConflictChecker.js | 84.87 | 81.65 | 100 | 84.87 | ...89,199,202,212,215,224,242,323
258
+ InternalFs.js | 87.59 | 73.5 | 88.88 | 87.5 | ...89,334,345,365,425-430,462,473
199
259
  Messages.js | 100 | 100 | 100 | 100 |
200
- Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
201
- Tree.js | 90.19 | 74.09 | 86.48 | 89.91 | ...39,466,476,530,622,630,661-672
260
+ Node.js | 68.03 | 58.39 | 79.59 | 67.22 | ...22,661-665,683,686,700-737,746
261
+ Tree.js | 89.94 | 75.91 | 85.36 | 89.81 | ...79,506,516,570,662,670,701-712
262
+ fileCipherLegacy.js | 100 | 100 | 100 | 100 |
263
+ index.js | 100 | 100 | 100 | 100 |
202
264
  -----------------------|---------|----------|---------|---------|-----------------------------------
203
265
   ELIFECYCLE  Test failed. See above for more details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secrez/fs",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,13 +8,13 @@
8
8
  "dependencies": {
9
9
  "@secrez/core": "~1.1.1",
10
10
  "@secrez/crypto": "~1.1.1",
11
- "@secrez/utils": "~1.1.1",
11
+ "@secrez/utils": "~1.1.2",
12
12
  "command-line-args": "^5.2.1",
13
13
  "fs-extra": "^9.1.0",
14
14
  "lodash": "^4.17.21"
15
15
  },
16
16
  "devDependencies": {
17
- "@secrez/test-helpers": "~2.0.4",
17
+ "@secrez/test-helpers": "~2.0.5",
18
18
  "chai": "^4.5.0",
19
19
  "cross-env": "^7.0.3",
20
20
  "mocha": "^10.8.2",
@@ -8,6 +8,10 @@ class GitConflictChecker {
8
8
  this.isGitRepo = null;
9
9
  this.remoteStatus = null;
10
10
  this.initialGitState = null; // Initial state captured at account entry
11
+ this.sessionBlock = null; // Known repo risk kept until Secrez is restarted
12
+ this.sessionBlockAnnounced = false;
13
+ this.entryStatus = null;
14
+ this.hasEntryStatus = false;
11
15
  this.lastCheck = null;
12
16
  this.checkInterval = 30000; // 30 seconds between checks
13
17
  }
@@ -36,6 +40,22 @@ class GitConflictChecker {
36
40
  */
37
41
  async captureInitialState() {
38
42
  const status = await this.getGitStatus();
43
+ this.entryStatus = status;
44
+ this.hasEntryStatus = true;
45
+ if (status && !status.error) {
46
+ this.initialGitState = this.getGitFingerprint(status);
47
+ }
48
+ return status;
49
+ }
50
+
51
+ /**
52
+ * Remember the repo after a push Secrez just made.
53
+ * The next write must fetch again: a commit can land on the remote after this.
54
+ */
55
+ async refreshFingerprint() {
56
+ const status = await this.getGitStatus();
57
+ this.entryStatus = null;
58
+ this.hasEntryStatus = false;
39
59
  if (status && !status.error) {
40
60
  this.initialGitState = this.getGitFingerprint(status);
41
61
  }
@@ -280,9 +300,7 @@ The git repository state has changed since you entered your account.
280
300
  This likely means a 'git pull' or other git operation was performed in another terminal.
281
301
 
282
302
  Secrez cannot safely read these changes while running.
283
- For data integrity, only READ operations and QUIT are allowed.
284
-
285
- Please quit Secrez and re-enter your account to sync with the new repository state.`;
303
+ For data integrity, only READ operations and QUIT are allowed.`;
286
304
  }
287
305
 
288
306
  if (status.error) {
@@ -299,10 +317,7 @@ Any changes you make now might conflict with remote changes that we cannot detec
299
317
  return `⚠️ Git Conflict Risk Detected!
300
318
 
301
319
  Your local repository is ${status.behind} commit(s) behind the remote '${status.remoteBranch}' branch.
302
- Any changes you make now could lead to merge conflicts when you try to sync later.
303
-
304
- Consider quitting Secrez and running in the container:
305
- git pull # to sync with remote changes first`;
320
+ Any changes you make now could lead to merge conflicts when you try to sync later.`;
306
321
  }
307
322
 
308
323
  return null;
@@ -315,6 +330,10 @@ Consider quitting Secrez and running in the container:
315
330
  this.isGitRepo = null;
316
331
  this.remoteStatus = null;
317
332
  this.initialGitState = null;
333
+ this.sessionBlock = null;
334
+ this.sessionBlockAnnounced = false;
335
+ this.entryStatus = null;
336
+ this.hasEntryStatus = false;
318
337
  this.lastCheck = null;
319
338
  }
320
339
  }
package/src/InternalFs.js CHANGED
@@ -201,6 +201,7 @@ class InternalFs {
201
201
  await this.moveOrUnlink(node, indexFrom, indexTo, fromTrash, entry);
202
202
  let originalParent = treeFrom.root.findChildById(originalParentId, true);
203
203
  originalParent.removeChild(node);
204
+ treeFrom.noteRemoved(node);
204
205
  if (cross) {
205
206
  entry.parent.add(node);
206
207
  }
@@ -379,6 +380,7 @@ class InternalFs {
379
380
  trash.root.add(node);
380
381
  }
381
382
  await this.moveOrUnlink(node, index, 1, fromTrash);
383
+ tree.noteRemoved(node);
382
384
  }
383
385
  await tree.save();
384
386
  await trash.save();
@@ -465,9 +467,20 @@ class InternalFs {
465
467
  }
466
468
 
467
469
  async checkGitSyncStatus() {
468
- // First, check for external repository changes WITHOUT using cache
469
- // This is critical - we must always get fresh git status to detect external changes
470
- const currentStatus = await this.gitConflictChecker.getGitStatus();
470
+ // Behind-remote and a hard block stay true until Secrez restarts, so later
471
+ // writes reuse the result instead of fetching again.
472
+ if (this.gitConflictChecker.sessionBlock) {
473
+ return this.gitConflictChecker.sessionBlock;
474
+ }
475
+
476
+ let currentStatus;
477
+ if (this.gitConflictChecker.hasEntryStatus) {
478
+ currentStatus = this.gitConflictChecker.entryStatus;
479
+ this.gitConflictChecker.hasEntryStatus = false;
480
+ this.gitConflictChecker.entryStatus = null;
481
+ } else {
482
+ currentStatus = await this.gitConflictChecker.getGitStatus();
483
+ }
471
484
  const riskInfo = this.gitConflictChecker.hasConflictRisk(currentStatus);
472
485
 
473
486
  if (riskInfo.hasRisk) {
@@ -475,13 +488,17 @@ class InternalFs {
475
488
  currentStatus,
476
489
  riskInfo
477
490
  );
478
- return {
491
+ const result = {
479
492
  hasRisk: true,
480
493
  riskType: riskInfo.type,
481
494
  allowBypass: riskInfo.allowBypass,
482
495
  message: warningMessage,
483
496
  status: currentStatus,
484
497
  };
498
+ if (riskInfo.allowBypass === false || riskInfo.type === "behind_remote") {
499
+ this.gitConflictChecker.sessionBlock = result;
500
+ }
501
+ return result;
485
502
  }
486
503
 
487
504
  return {
package/src/Node.js CHANGED
@@ -103,19 +103,29 @@ class Node {
103
103
  if (typeof json === "string") {
104
104
  json = JSON.parse(json);
105
105
  }
106
+ // Full encrypted names of blobs that left this dataset. Absent on older indexes.
107
+ let removed = Array.isArray(json.r)
108
+ ? json.r.filter((name) => typeof name === "string" && name)
109
+ : [];
106
110
 
107
- for (let c of json.c) {
111
+ for (let c of json.c || []) {
108
112
  if (c.v[0]) {
109
113
  minSize = c.v[0].length;
110
114
  break;
111
115
  }
112
116
  }
117
+ let removedSet = new Set(removed);
113
118
  let files = {};
114
119
  for (let f of allFiles) {
120
+ // A removed blob must not steal the prefix of a file created later.
121
+ if (removedSet.has(f)) continue;
115
122
  files[f.substring(0, minSize)] = f;
116
123
  }
117
124
  json = Node.preFormat(json, secrez, files);
118
125
  let root = Node.initNode(json);
126
+ if (root) {
127
+ root.removed = removed;
128
+ }
119
129
  return root;
120
130
  }
121
131
 
@@ -217,6 +227,13 @@ class Node {
217
227
 
218
228
  if (Node.isRoot(this)) {
219
229
  minSize = this.calculateMinSize(allFiles);
230
+ let live = new Set(this.getAllFiles());
231
+ let removed = (this.removed || []).filter(
232
+ (name) => name && !live.has(name)
233
+ );
234
+ if (removed.length) {
235
+ result.r = removed.slice().sort();
236
+ }
220
237
  }
221
238
 
222
239
  if (this.versions) {
package/src/Tree.js CHANGED
@@ -112,7 +112,7 @@ class Tree {
112
112
 
113
113
  // verify the tree
114
114
  let allFilesOnTree = Tree.getAllFilesOnTree(this.root).sort();
115
- const filesNotOnTree = [];
115
+ let filesNotOnTree = [];
116
116
  for (let i = 0; i < allSecretsFiles.length; i++) {
117
117
  let file = allSecretsFiles[i];
118
118
  if (!allFilesOnTree.includes(file)) {
@@ -120,28 +120,18 @@ class Tree {
120
120
  }
121
121
  }
122
122
  if (filesNotOnTree.length) {
123
- let toBeRecovered = {};
124
- let recoveredEntries = [];
125
- FOR: for (let i = 1; i < allIndexes.length; i++) {
123
+ let olderRoots = [];
124
+ for (let i = 1; i < allIndexes.length; i++) {
126
125
  json = JSON.parse(allIndexes[i].content);
127
126
  let root = Node.fromJSON(json, this.secrez, allSecretsFiles);
128
- allFilesOnTree = Tree.getAllFilesOnTree(root).sort();
129
- for (let j = 0; j < filesNotOnTree.length; j++) {
130
- let f = filesNotOnTree[j];
131
- if (allFilesOnTree.includes(f.encryptedName)) {
132
- let node = root.findChildById(f.id);
133
- if (node) {
134
- let k = allSecretsFiles.indexOf(f.encryptedName);
135
- toBeRecovered[node.getPath()] = allSecrets[k];
136
- filesNotOnTree.splice(j, 1);
137
- j--;
138
- }
139
- }
140
- if (!files.length) {
141
- break FOR;
142
- }
143
- }
127
+ if (root) olderRoots.push(root);
144
128
  }
129
+ let { toBeRecovered, unknown } = this.classifyMissing(
130
+ filesNotOnTree,
131
+ olderRoots
132
+ );
133
+ let recoveredEntries = [];
134
+ filesNotOnTree = unknown;
145
135
  let paths = Object.keys(toBeRecovered).sort();
146
136
  for (let p of paths) {
147
137
  let entry = toBeRecovered[p];
@@ -212,6 +202,51 @@ class Tree {
212
202
  this.status = Tree.statutes.LOADED;
213
203
  }
214
204
 
205
+ noteRemoved(node) {
206
+ if (!node || typeof node.getAllFiles !== "function") return;
207
+ this.noteRemovedFiles(node.getAllFiles());
208
+ }
209
+
210
+ noteRemovedFile(encryptedName) {
211
+ this.noteRemovedFiles([encryptedName]);
212
+ }
213
+
214
+ noteRemovedFiles(names) {
215
+ if (!this.root.removed) this.root.removed = [];
216
+ let live = new Set(this.root.getAllFiles());
217
+ for (let name of names || []) {
218
+ if (!name || live.has(name) || this.root.removed.includes(name)) continue;
219
+ this.root.removed.push(name);
220
+ }
221
+ }
222
+
223
+ // Newest mention wins. A blob listed in `r` stays out unless a newer index
224
+ // still has it as a live file. Blobs no index mentions stay unknown.
225
+ classifyMissing(filesNotOnTree, olderRoots) {
226
+ let decision = new Map();
227
+ for (let root of [this.root, ...(olderRoots || [])]) {
228
+ for (let name of Tree.getAllFilesOnTree(root)) {
229
+ if (!decision.has(name)) decision.set(name, { present: true, root });
230
+ }
231
+ for (let name of root.removed || []) {
232
+ if (!decision.has(name)) decision.set(name, { present: false });
233
+ }
234
+ }
235
+ let toBeRecovered = {};
236
+ let unknown = [];
237
+ for (let entry of filesNotOnTree) {
238
+ let found = decision.get(entry.encryptedName);
239
+ if (!found) {
240
+ unknown.push(entry);
241
+ } else if (found.present && found.root !== this.root) {
242
+ let node = found.root.findChildById(entry.id);
243
+ if (node) toBeRecovered[node.getPath()] = entry;
244
+ else unknown.push(entry);
245
+ }
246
+ }
247
+ return { toBeRecovered, unknown };
248
+ }
249
+
215
250
  optimizeResults(entries) {
216
251
  entries.reverse();
217
252
  for (let i = 0; i < entries.length; i++) {