@fnndsc/salsa 4.5.6 → 4.6.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.
Files changed (158) hide show
  1. package/README.md +0 -2
  2. package/dist/compute/index.d.ts +0 -9
  3. package/dist/compute/index.js +0 -16
  4. package/dist/compute/index.js.map +1 -1
  5. package/dist/dag/feedData.js +166 -73
  6. package/dist/dag/feedData.js.map +1 -1
  7. package/dist/dag/feedLoad.d.ts +1 -1
  8. package/dist/dag/feedLoad.js +6 -4
  9. package/dist/dag/feedLoad.js.map +1 -1
  10. package/dist/dicom/pixels.js +95 -36
  11. package/dist/dicom/pixels.js.map +1 -1
  12. package/dist/dicom/series.d.ts +4 -1
  13. package/dist/dicom/series.js +80 -31
  14. package/dist/dicom/series.js.map +1 -1
  15. package/dist/dicom/tags.d.ts +28 -0
  16. package/dist/dicom/tags.js +30 -0
  17. package/dist/dicom/tags.js.map +1 -1
  18. package/dist/files/copy.d.ts +197 -0
  19. package/dist/files/copy.js +636 -0
  20. package/dist/files/copy.js.map +1 -0
  21. package/dist/files/copyFolder.d.ts +103 -0
  22. package/dist/files/copyFolder.js +199 -0
  23. package/dist/files/copyFolder.js.map +1 -0
  24. package/dist/files/create.d.ts +178 -0
  25. package/dist/files/create.js +444 -0
  26. package/dist/files/create.js.map +1 -0
  27. package/dist/files/download.d.ts +188 -0
  28. package/dist/files/download.js +541 -0
  29. package/dist/files/download.js.map +1 -0
  30. package/dist/files/index.d.ts +69 -141
  31. package/dist/files/index.js +184 -535
  32. package/dist/files/index.js.map +1 -1
  33. package/dist/files/listing.d.ts +132 -0
  34. package/dist/files/listing.js +179 -0
  35. package/dist/files/listing.js.map +1 -0
  36. package/dist/files/move.d.ts +125 -0
  37. package/dist/files/move.js +334 -0
  38. package/dist/files/move.js.map +1 -0
  39. package/dist/files/pathMapper.d.ts +24 -1
  40. package/dist/files/pathMapper.js +108 -47
  41. package/dist/files/pathMapper.js.map +1 -1
  42. package/dist/files/proof.d.ts +315 -0
  43. package/dist/files/proof.js +574 -0
  44. package/dist/files/proof.js.map +1 -0
  45. package/dist/files/removal.d.ts +223 -0
  46. package/dist/files/removal.js +318 -0
  47. package/dist/files/removal.js.map +1 -0
  48. package/dist/files/replace.d.ts +175 -0
  49. package/dist/files/replace.js +582 -0
  50. package/dist/files/replace.js.map +1 -0
  51. package/dist/files/upload.d.ts +205 -0
  52. package/dist/files/upload.js +478 -0
  53. package/dist/files/upload.js.map +1 -0
  54. package/dist/index.d.ts +14 -2
  55. package/dist/index.js +45 -32
  56. package/dist/index.js.map +1 -1
  57. package/dist/jobs/index.d.ts +1 -1
  58. package/dist/jobs/index.js +2 -2
  59. package/dist/jobs/index.js.map +1 -1
  60. package/dist/jobs/jobOps.d.ts +20 -13
  61. package/dist/jobs/jobOps.js +41 -37
  62. package/dist/jobs/jobOps.js.map +1 -1
  63. package/dist/pacs/anonymise.d.ts +17 -36
  64. package/dist/pacs/anonymise.js +29 -67
  65. package/dist/pacs/anonymise.js.map +1 -1
  66. package/dist/pipelines/index.d.ts +1 -13
  67. package/dist/pipelines/index.js +0 -38
  68. package/dist/pipelines/index.js.map +1 -1
  69. package/dist/pipelines/invocation.js +321 -167
  70. package/dist/pipelines/invocation.js.map +1 -1
  71. package/dist/pipelines/manifest.js.map +1 -1
  72. package/dist/pipelines/packages.d.ts +11 -8
  73. package/dist/pipelines/packages.js +253 -77
  74. package/dist/pipelines/packages.js.map +1 -1
  75. package/dist/plugins/adminToken.d.ts +67 -0
  76. package/dist/plugins/adminToken.js +77 -0
  77. package/dist/plugins/adminToken.js.map +1 -0
  78. package/dist/plugins/index.d.ts +0 -7
  79. package/dist/plugins/index.js +0 -16
  80. package/dist/plugins/index.js.map +1 -1
  81. package/dist/plugins/peer_search.d.ts +0 -15
  82. package/dist/plugins/peer_search.js +0 -25
  83. package/dist/plugins/peer_search.js.map +1 -1
  84. package/dist/plugins/plugin_add.d.ts +14 -2
  85. package/dist/plugins/plugin_add.js +42 -13
  86. package/dist/plugins/plugin_add.js.map +1 -1
  87. package/dist/plugins/plugin_docker.d.ts +25 -0
  88. package/dist/plugins/plugin_docker.js +33 -0
  89. package/dist/plugins/plugin_docker.js.map +1 -1
  90. package/dist/plugins/plugin_register.d.ts +0 -10
  91. package/dist/plugins/plugin_register.js +3 -54
  92. package/dist/plugins/plugin_register.js.map +1 -1
  93. package/dist/plugins/plugin_sync.js +45 -22
  94. package/dist/plugins/plugin_sync.js.map +1 -1
  95. package/dist/plugins/plugin_validate.js +47 -13
  96. package/dist/plugins/plugin_validate.js.map +1 -1
  97. package/dist/plugins/store_import.d.ts +0 -9
  98. package/dist/plugins/store_import.js +3 -29
  99. package/dist/plugins/store_import.js.map +1 -1
  100. package/dist/retrieve/task.d.ts +137 -0
  101. package/dist/retrieve/task.js +41 -0
  102. package/dist/retrieve/task.js.map +1 -0
  103. package/dist/retrieve/watch.d.ts +2 -118
  104. package/dist/retrieve/watch.js +452 -321
  105. package/dist/retrieve/watch.js.map +1 -1
  106. package/dist/vfs/providers/etc.d.ts +6 -4
  107. package/dist/vfs/providers/etc.js +12 -4
  108. package/dist/vfs/providers/etc.js.map +1 -1
  109. package/dist/vfs/providers/native.d.ts +116 -39
  110. package/dist/vfs/providers/native.js +291 -347
  111. package/dist/vfs/providers/native.js.map +1 -1
  112. package/dist/vfs/providers/pacs.d.ts +29 -3
  113. package/dist/vfs/providers/pacs.js +303 -73
  114. package/dist/vfs/providers/pacs.js.map +1 -1
  115. package/dist/vfs/providers/pacs_content.js +22 -6
  116. package/dist/vfs/providers/pacs_content.js.map +1 -1
  117. package/dist/vfs/providers/proc/backfill.d.ts +46 -0
  118. package/dist/vfs/providers/proc/backfill.js +147 -0
  119. package/dist/vfs/providers/proc/backfill.js.map +1 -0
  120. package/dist/vfs/providers/proc/book.d.ts +176 -0
  121. package/dist/vfs/providers/proc/book.js +73 -0
  122. package/dist/vfs/providers/proc/book.js.map +1 -0
  123. package/dist/vfs/providers/proc/catchup.d.ts +69 -0
  124. package/dist/vfs/providers/proc/catchup.js +125 -0
  125. package/dist/vfs/providers/proc/catchup.js.map +1 -0
  126. package/dist/vfs/providers/proc/feedIndex.d.ts +146 -0
  127. package/dist/vfs/providers/proc/feedIndex.js +354 -0
  128. package/dist/vfs/providers/proc/feedIndex.js.map +1 -0
  129. package/dist/vfs/providers/proc/feedTopology.d.ts +85 -0
  130. package/dist/vfs/providers/proc/feedTopology.js +192 -0
  131. package/dist/vfs/providers/proc/feedTopology.js.map +1 -0
  132. package/dist/vfs/providers/proc/locate.d.ts +60 -0
  133. package/dist/vfs/providers/proc/locate.js +103 -0
  134. package/dist/vfs/providers/proc/locate.js.map +1 -0
  135. package/dist/vfs/providers/proc/path.d.ts +50 -0
  136. package/dist/vfs/providers/proc/path.js +106 -0
  137. package/dist/vfs/providers/proc/path.js.map +1 -0
  138. package/dist/vfs/providers/proc/roster.d.ts +95 -0
  139. package/dist/vfs/providers/proc/roster.js +425 -0
  140. package/dist/vfs/providers/proc/roster.js.map +1 -0
  141. package/dist/vfs/providers/proc/rows.d.ts +120 -0
  142. package/dist/vfs/providers/proc/rows.js +181 -0
  143. package/dist/vfs/providers/proc/rows.js.map +1 -0
  144. package/dist/vfs/providers/proc/subtree.d.ts +73 -0
  145. package/dist/vfs/providers/proc/subtree.js +125 -0
  146. package/dist/vfs/providers/proc/subtree.js.map +1 -0
  147. package/dist/vfs/providers/proc/sweep.d.ts +89 -0
  148. package/dist/vfs/providers/proc/sweep.js +297 -0
  149. package/dist/vfs/providers/proc/sweep.js.map +1 -0
  150. package/dist/vfs/providers/proc.d.ts +47 -346
  151. package/dist/vfs/providers/proc.js +349 -1806
  152. package/dist/vfs/providers/proc.js.map +1 -1
  153. package/dist/vfs/providers/share.js +4 -1
  154. package/dist/vfs/providers/share.js.map +1 -1
  155. package/package.json +3 -3
  156. package/dist/pacs/resultDecode.d.ts +0 -13
  157. package/dist/pacs/resultDecode.js +0 -19
  158. package/dist/pacs/resultDecode.js.map +0 -1
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ /**
3
+ * @file Moving what holds a CUBE path: the proved holder, by its id, to a name chosen here alone.
4
+ *
5
+ * A move is decided on proofs, each made once: what holds the source, what
6
+ * holds the destination, and what holds the place the entry will take (the
7
+ * destination itself, or a name inside it when it is a folder). The final
8
+ * name is chosen in this module and nowhere else: into a destination that
9
+ * is a folder, or one written with a trailing slash, the entry keeps its
10
+ * name. Then the proved holder moves by its id, at CUBE's own address for
11
+ * it, a file through `file_moveById`, whose older field is tried only
12
+ * after the place is shown free again. A file is moved only from the path
13
+ * it was proved at: one moved or replaced since is not this move's to take.
14
+ *
15
+ * A folder is moved only from the path it was proved at, too, and never
16
+ * into itself or below itself (`EINVAL`). A link is not moved: it is
17
+ * removed and made again. The proofs and the move go to one client, the
18
+ * session's when the source was proved; a connection that changed before
19
+ * the move refuses it, and every request that changes anything is asked
20
+ * only while the bound client is still the session's, asked immediately
21
+ * before it.
22
+ *
23
+ * CUBE has no move that refuses a held destination, so the proof and the
24
+ * move are two requests and something can arrive between them
25
+ * (docs/CUBE-gaps.adoc). Every proof here is made on the bound client,
26
+ * each parent found fresh on it, never through the memo of folder lookups.
27
+ *
28
+ * Key components:
29
+ * - holder_move: move a proved holder, naming it as asked.
30
+ * - path_move: prove a source, then move it (the native mount's rename).
31
+ * - files_move: the public two-path move, with mv's naming.
32
+ * - parentFolder_prove: whether a place's parent is a folder, proved on a bound client.
33
+ *
34
+ * Typical usage:
35
+ * ```ts
36
+ * const moved: boolean = await files_move('/home/ada/a.txt', '/home/ada/archive/');
37
+ * ```
38
+ *
39
+ * Dependencies: the proofs of `./proof.js`, cumin's `chrisIO` (the session's
40
+ * client, bound as a `HolderClient`: a folder's and a file's move by id, a
41
+ * file's place by id), fond's outcome, and the path mapper, cleared by a
42
+ * move asked.
43
+ *
44
+ * @module
45
+ */
46
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
47
+ if (k2 === undefined) k2 = k;
48
+ var desc = Object.getOwnPropertyDescriptor(m, k);
49
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
50
+ desc = { enumerable: true, get: function() { return m[k]; } };
51
+ }
52
+ Object.defineProperty(o, k2, desc);
53
+ }) : (function(o, m, k, k2) {
54
+ if (k2 === undefined) k2 = k;
55
+ o[k2] = m[k];
56
+ }));
57
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
58
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
59
+ }) : function(o, v) {
60
+ o["default"] = v;
61
+ });
62
+ var __importStar = (this && this.__importStar) || (function () {
63
+ var ownKeys = function(o) {
64
+ ownKeys = Object.getOwnPropertyNames || function (o) {
65
+ var ar = [];
66
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
67
+ return ar;
68
+ };
69
+ return ownKeys(o);
70
+ };
71
+ return function (mod) {
72
+ if (mod && mod.__esModule) return mod;
73
+ var result = {};
74
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
75
+ __setModuleDefault(result, mod);
76
+ return result;
77
+ };
78
+ })();
79
+ Object.defineProperty(exports, "__esModule", { value: true });
80
+ exports.parentFolder_prove = parentFolder_prove;
81
+ exports.destination_isWithin = destination_isWithin;
82
+ exports.holder_move = holder_move;
83
+ exports.path_move = path_move;
84
+ exports.files_move = files_move;
85
+ const path = __importStar(require("path"));
86
+ const cumin_1 = require("@fnndsc/cumin");
87
+ const fond_1 = require("@fnndsc/fond");
88
+ const pathMapper_js_1 = require("./pathMapper.js");
89
+ const proof_js_1 = require("./proof.js");
90
+ /**
91
+ * The failure a proof met, as an outcome.
92
+ *
93
+ * @param answer - The failed proof.
94
+ * @returns `ENOTDIR` for a file on the way, `EIO` otherwise, with the stacked reason.
95
+ */
96
+ function proofFailure_outcome(answer) {
97
+ return (0, fond_1.vfs_failFromStack)(answer.notDirectory ? 'ENOTDIR' : 'EIO');
98
+ }
99
+ /**
100
+ * The refusal of a destination something already holds.
101
+ *
102
+ * @param place - The place.
103
+ * @param held - What holds it.
104
+ * @returns `EEXIST`, naming what is there.
105
+ */
106
+ function destinationHeld_refuse(place, held) {
107
+ const what = held.kind === 'held' ? `a ${held.holder.kind === 'dir' ? 'folder' : held.holder.kind}` : held.kind === 'ambiguous' ? (0, proof_js_1.holders_describe)(held.holders) : 'nothing';
108
+ return (0, fond_1.vfs_fail)('EEXIST', `Destination exists: ${place} — mise cannot overwrite ${what}; remove it first`);
109
+ }
110
+ /**
111
+ * Whether a place's parent is a folder that is there, proved fresh on the
112
+ * client an act is bound to.
113
+ *
114
+ * @param acts - The client the act is bound to.
115
+ * @param place - The place.
116
+ * @returns Done, or why not (`ENOENT`, `ENOTDIR`, `EPERM`, `EIO`).
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const parent: VfsOutcome = await parentFolder_prove(acts, '/home/ada/new.txt');
121
+ * ```
122
+ */
123
+ async function parentFolder_prove(acts, place) {
124
+ const parent = await (0, proof_js_1.pathHolders_answer)(path.posix.dirname(place), acts);
125
+ if (parent.kind === 'error')
126
+ return proofFailure_outcome(parent);
127
+ if (parent.kind === 'absent')
128
+ return (0, fond_1.vfs_fail)('ENOENT');
129
+ if (parent.kind === 'ambiguous')
130
+ return (0, fond_1.vfs_fail)('EPERM', `${(0, proof_js_1.holders_describe)(parent.holders)} share ${path.posix.dirname(place)}, and nothing is moved into it`);
131
+ return parent.holder.kind === 'dir' ? (0, fond_1.vfs_ok)(true) : (0, fond_1.vfs_fail)('ENOTDIR');
132
+ }
133
+ /**
134
+ * The name a move gives its entry, on proof that the name is free and its
135
+ * folder is there: the one place the final name is chosen.
136
+ *
137
+ * @param acts - The client the source was proved with: every proof here is made fresh on it.
138
+ * @param src - The source's path.
139
+ * @param dest - The destination as asked.
140
+ * @param naming - mv's naming, and whether a trailing slash was written.
141
+ * @returns The final path, or why the move may not be made.
142
+ */
143
+ async function destination_settle(acts, src, dest, naming) {
144
+ const there = await (0, proof_js_1.pathHolders_answer)(dest, acts);
145
+ if (there.kind === 'error')
146
+ return proofFailure_outcome(there);
147
+ const folder = there.kind === 'held' && there.holder.kind === 'dir';
148
+ if (naming.intoFolder === true && !folder)
149
+ return (0, fond_1.vfs_fail)(there.kind === 'absent' ? 'ENOENT' : 'ENOTDIR');
150
+ if (folder && (naming.intoFolder === true || naming.mvNaming === true)) {
151
+ // Its folder is `dest`, proved a folder just now.
152
+ const inside = path.posix.join(dest, path.posix.basename(src));
153
+ const taken = await (0, proof_js_1.pathHolders_answer)(inside, acts);
154
+ if (taken.kind === 'error')
155
+ return proofFailure_outcome(taken);
156
+ return taken.kind === 'absent' ? (0, fond_1.vfs_ok)(inside) : destinationHeld_refuse(inside, taken);
157
+ }
158
+ if (there.kind !== 'absent')
159
+ return destinationHeld_refuse(dest, there);
160
+ const parent = await parentFolder_prove(acts, dest);
161
+ return parent.ok ? (0, fond_1.vfs_ok)(dest) : parent;
162
+ }
163
+ /**
164
+ * Whether CUBE says a file is at a path, asked by the file's id.
165
+ *
166
+ * @param acts - The client the source was proved with.
167
+ * @param fileId - The file.
168
+ * @param expected - The path it was proved at.
169
+ * @returns True only when CUBE answered and named that path.
170
+ */
171
+ async function file_isAt(acts, fileId, expected) {
172
+ const where = await acts.file_locate(fileId);
173
+ return where.ok && where.value === expected;
174
+ }
175
+ /** The refusal of a move whose client is no longer the session's. */
176
+ const CONNECTION_CHANGED = 'the connection to CUBE changed after the source was proved: nothing was moved';
177
+ /**
178
+ * Moves a proved file to a settled final path, by its id, only from the
179
+ * path it was proved at.
180
+ *
181
+ * @param acts - The client the source was proved with.
182
+ * @param holder - The file.
183
+ * @param src - The path it was proved at.
184
+ * @param final - Where it goes.
185
+ * @returns Done, or why not.
186
+ */
187
+ async function file_moveTo(acts, holder, src, final) {
188
+ if (!await file_isAt(acts, holder.id, src)) {
189
+ return (0, fond_1.vfs_fail)('EIO', `the file proved at ${src} (id ${String(holder.id)}) is no longer seen there: nothing was moved, and what is at ${src} now is left alone`);
190
+ }
191
+ // Before an older CUBE's second spelling is tried: the file still where it
192
+ // was proved, and the place still free. The place is proved on the
193
+ // session's connection, so the proof counts only when the bound client is
194
+ // the session's both before it is begun and after it is answered; the move
195
+ // asks once more immediately before its second request.
196
+ const place_recheck = async () => {
197
+ if (!await file_isAt(acts, holder.id, src) || !await acts.current_is())
198
+ return false;
199
+ const free = await (0, proof_js_1.pathHolders_prove)(final, acts);
200
+ if (!await acts.current_is())
201
+ return false;
202
+ return free.ok && free.value.kind === 'absent';
203
+ };
204
+ if (!await acts.current_is())
205
+ return (0, fond_1.vfs_fail)('EIO', CONNECTION_CHANGED);
206
+ const moved = await acts.file_moveById(holder.id, final, place_recheck, holder.href);
207
+ return moved.ok ? (0, fond_1.vfs_ok)(true) : (0, fond_1.vfs_failFromStack)('EIO');
208
+ }
209
+ /**
210
+ * Moves the proved holder to a settled final path, by its id.
211
+ *
212
+ * @param acts - The client the source was proved with.
213
+ * @param holder - The holder.
214
+ * @param src - The path it was proved at.
215
+ * @param final - Where it goes.
216
+ * @returns Done, or why not.
217
+ */
218
+ async function holder_moveTo(acts, holder, src, final) {
219
+ if (holder.kind === 'link')
220
+ return (0, fond_1.vfs_fail)('EPERM', `${src} is a link, and a link cannot be moved; remove it and make it again: nothing was moved`);
221
+ if (holder.kind !== 'dir')
222
+ return file_moveTo(acts, holder, src, final);
223
+ if (holder.id === 0)
224
+ return (0, fond_1.vfs_fail)('EPERM', 'the root is not moved');
225
+ if (!await acts.current_is())
226
+ return (0, fond_1.vfs_fail)('EIO', CONNECTION_CHANGED);
227
+ const moved = await acts.folder_moveById(holder.id, src, final, holder.href);
228
+ if (!moved.ok)
229
+ return (0, fond_1.vfs_failFromStack)('EIO');
230
+ return moved.value ? (0, fond_1.vfs_ok)(true) : (0, fond_1.vfs_fail)('ENOENT', `${src} was proved a folder (id ${String(holder.id)}), and CUBE no longer has it: nothing was moved`);
231
+ }
232
+ /**
233
+ * Whether a destination is the source itself or lies inside it.
234
+ *
235
+ * @param src - The source's path.
236
+ * @param dest - The destination.
237
+ * @returns True when a move or a copy there would put the source into itself.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * destination_isWithin('/home/ada/a', '/home/ada/a/b'); // true
242
+ * ```
243
+ */
244
+ function destination_isWithin(src, dest) {
245
+ return dest === src || dest.startsWith(src === '/' ? '/' : `${src}/`);
246
+ }
247
+ /**
248
+ * Moves a proved holder, naming it as asked: the destination is proved, the
249
+ * final name chosen (into a folder the entry keeps its name, under mv's
250
+ * naming or a trailing slash), that place proved free and its folder there,
251
+ * the caller's check asked of that place (another mount's is `EXDEV`), and
252
+ * the holder moved by its id. A destination that is the source, or lies
253
+ * inside it, is `EINVAL`.
254
+ *
255
+ * @param acts - The client the source was proved with.
256
+ * @param holder - What holds the source, as its proof named it.
257
+ * @param src - The absolute path it was proved at.
258
+ * @param dest - The absolute destination.
259
+ * @param naming - mv's naming, and whether the destination was written with a trailing slash.
260
+ * @returns Done, or why not (`EEXIST`, `EINVAL`, `ENOENT`, `ENOTDIR`, `EPERM`, `EIO`).
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * const moved: VfsOutcome = await holder_move(acts, { kind: 'file', id: 41, href: null }, '/home/ada/a.txt', '/home/ada/docs', { mvNaming: true });
265
+ * ```
266
+ */
267
+ async function holder_move(acts, holder, src, dest, naming = {}) {
268
+ if (destination_isWithin(src, dest))
269
+ return (0, fond_1.vfs_fail)('EINVAL', `cannot move ${src} to ${dest}: a destination inside what is moved`);
270
+ const final = await destination_settle(acts, src, dest, naming);
271
+ if (!final.ok)
272
+ return final;
273
+ const allowed = naming.finalPath_check?.(final.value) ?? (0, fond_1.vfs_ok)(true);
274
+ if (!allowed.ok)
275
+ return allowed;
276
+ const moved = await holder_moveTo(acts, holder, src, final.value);
277
+ // Asked, and perhaps done: no mapping, under any name, may lead through the old path or miss the new one.
278
+ (0, pathMapper_js_1.linkCache_clear)();
279
+ return moved;
280
+ }
281
+ /**
282
+ * Moves what holds a path: the source proved here, on the client every act
283
+ * after goes to, and the rest ({@link holder_move}).
284
+ *
285
+ * @param src - The absolute source path.
286
+ * @param dest - The absolute destination.
287
+ * @param naming - mv's naming, and whether the destination was written with a trailing slash.
288
+ * @returns Done, or why not.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * const moved: VfsOutcome = await path_move('/home/ada/a.txt', '/home/ada/docs', { mvNaming: true });
293
+ * ```
294
+ */
295
+ async function path_move(src, dest, naming = {}) {
296
+ const bound = await cumin_1.chrisIO.holderClient_bind();
297
+ if (!bound.ok)
298
+ return (0, fond_1.vfs_failFromStack)('EIO');
299
+ const proof = await (0, proof_js_1.pathHolders_answer)(src, bound.value);
300
+ if (proof.kind === 'error')
301
+ return proofFailure_outcome(proof);
302
+ if (!await bound.value.current_is())
303
+ return (0, fond_1.vfs_fail)('EIO', CONNECTION_CHANGED);
304
+ if (proof.kind === 'absent')
305
+ return (0, fond_1.vfs_fail)('ENOENT', `Source not found: ${src}`);
306
+ if (proof.kind === 'ambiguous')
307
+ return (0, fond_1.vfs_fail)('EPERM', `${(0, proof_js_1.holders_describe)(proof.holders)} share ${src}, and neither is moved`);
308
+ return holder_move(bound.value, proof.holder, src, dest, naming);
309
+ }
310
+ /**
311
+ * Moves a file or a folder, by its path, with mv's naming: into an existing
312
+ * folder, or a destination written with a trailing slash, it keeps its name.
313
+ * The move is {@link path_move}'s.
314
+ *
315
+ * @param srcPath - The source path.
316
+ * @param destPath - The destination path; a trailing slash means "into this folder".
317
+ * @returns True when CUBE moved it; false otherwise, with the reason on the error stack.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * const moved: boolean = await files_move('/home/ada/a.txt', '/home/ada/archive/');
322
+ * ```
323
+ */
324
+ async function files_move(srcPath, destPath) {
325
+ const src = path.posix.resolve('/', srcPath);
326
+ const dest = path.posix.resolve('/', destPath);
327
+ const intoFolder = destPath.endsWith('/') && dest !== '/';
328
+ const moved = await path_move(src, dest, { mvNaming: true, intoFolder });
329
+ if (moved.ok)
330
+ return true;
331
+ cumin_1.errorStack.stack_push('error', (0, fond_1.vfsRefusal_text)('rename', moved, src, dest));
332
+ return false;
333
+ }
334
+ //# sourceMappingURL=move.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move.js","sourceRoot":"","sources":["../../src/files/move.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CH,gDAMC;AA0GD,oDAEC;AAsBD,kCAUC;AAgBD,8BASC;AAgBD,gCAQC;AA9OD,2CAA6B;AAE7B,yCAAoF;AACpF,uCAAyH;AAEzH,mDAAkD;AAClD,yCAAgK;AAEhK;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAoB;IAChD,OAAO,IAAA,wBAAiB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,KAAa,EAAE,IAAe;IAC5D,MAAM,IAAI,GAAW,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAA,2BAAgB,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrL,OAAO,IAAA,eAAQ,EAAC,QAAQ,EAAE,uBAAuB,KAAK,4BAA4B,IAAI,mBAAmB,CAAC,CAAC;AAC7G,CAAC;AAED;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,kBAAkB,CAAC,IAAkB,EAAE,KAAa;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11
11
  * This eliminates redundant tree walking and API calls for paths with common prefixes.
12
12
  *
13
+ * What a link leads to is what one identity is shown: the mappings are the
14
+ * session's identity's, emptied when it changes, and neither read nor kept
15
+ * by work done as another user (`sudo`) or begun under an identity since
16
+ * replaced.
17
+ *
13
18
  * It is CUBE's own mechanics (a `.chrislink` is a file CUBE lists among a
14
19
  * folder's links), so it lives with the file reads. The kernel asks it
15
20
  * through one door: the ChRIS backend's link walk, which brasa's
@@ -130,6 +135,7 @@ export declare class PathMapper {
130
135
  * @param suffix - The path suffix to resolve (e.g., 'feed_4/files').
131
136
  * @param physicalBase - The physical base path to build upon.
132
137
  * @param logicalBase - The logical base path (for caching intermediate results).
138
+ * @param began - The identity epoch the resolution was begun under.
133
139
  * @returns Result containing the resolved physical path.
134
140
  */
135
141
  private suffix_resolve;
@@ -142,6 +148,7 @@ export declare class PathMapper {
142
148
  *
143
149
  * @param candidatePhysical - The physical path to check.
144
150
  * @param candidateLogical - The logical path (used for cache lookup).
151
+ * @param began - The identity epoch the resolution was begun under.
145
152
  * @returns The link target if it's a link, null otherwise.
146
153
  */
147
154
  private link_checkAndResolve;
@@ -150,6 +157,7 @@ export declare class PathMapper {
150
157
  * seeing their links.
151
158
  *
152
159
  * @param logicalPath - The path just resolved.
160
+ * @param began - The identity epoch the resolution was begun under.
153
161
  */
154
162
  private blind_note;
155
163
  /**
@@ -157,6 +165,9 @@ export declare class PathMapper {
157
165
  * last call, emptied by the call. A command whose answer failed reports
158
166
  * them: a link in one of them, had it been seen, would have led elsewhere.
159
167
  *
168
+ * Work done as another user, or begun under an identity since replaced,
169
+ * is told none and empties nothing: they are the session's identity's.
170
+ *
160
171
  * @returns The parents, in the order first met.
161
172
  */
162
173
  blindParents_take(): string[];
@@ -170,11 +181,23 @@ export declare class PathMapper {
170
181
  /**
171
182
  * Caches a logical-to-physical path mapping.
172
183
  *
184
+ * Kept only from the session's own identity's work, and only when the
185
+ * identity has not changed since the resolution began.
186
+ *
173
187
  * @param logicalPath - The logical path.
174
188
  * @param physicalPath - The corresponding physical path.
175
- * @param ttl - Optional TTL in milliseconds (defaults to 30s).
189
+ * @param began - The identity epoch the resolution was begun under.
176
190
  */
177
191
  private cache_set;
192
+ /**
193
+ * Whether a resolution may still change what the session's identity is
194
+ * told: it is not another user's work, and the identity has not changed
195
+ * since it began.
196
+ *
197
+ * @param began - The identity epoch the resolution was begun under.
198
+ * @returns True while the resolution is the session's current work.
199
+ */
200
+ private walk_current;
178
201
  /**
179
202
  * Invalidates all cached mappings with a given logical path prefix.
180
203
  *