@noldova/checkpoints 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +17 -2
- package/module.json +15 -0
- package/package.json +49 -4
- package/settings.json +15 -0
- package/src/api/index.d.ts +1150 -0
- package/src/api/index.js +34 -0
- package/src/api/index.js.map +1 -0
- package/src/exceptions/checkpoint-file-missing.exception.js +17 -0
- package/src/exceptions/checkpoint-file-missing.exception.js.map +1 -0
- package/src/exceptions/checkpoints.exception.js +14 -0
- package/src/exceptions/checkpoints.exception.js.map +1 -0
- package/src/exceptions/git-exited.exception.js +21 -0
- package/src/exceptions/git-exited.exception.js.map +1 -0
- package/src/exceptions/git-manifest-invalid.exception.js +18 -0
- package/src/exceptions/git-manifest-invalid.exception.js.map +1 -0
- package/src/exceptions/git-missing.exception.js +18 -0
- package/src/exceptions/git-missing.exception.js.map +1 -0
- package/src/exceptions/git-stopped.exception.js +19 -0
- package/src/exceptions/git-stopped.exception.js.map +1 -0
- package/src/exceptions/git.exception.js +14 -0
- package/src/exceptions/git.exception.js.map +1 -0
- package/src/exceptions/ignore-rules-mismatch.exception.js +17 -0
- package/src/exceptions/ignore-rules-mismatch.exception.js.map +1 -0
- package/src/exceptions/journal-field-missing.exception.js +19 -0
- package/src/exceptions/journal-field-missing.exception.js.map +1 -0
- package/src/exceptions/restore-folder-changed.exception.js +19 -0
- package/src/exceptions/restore-folder-changed.exception.js.map +1 -0
- package/src/exceptions/restore-path-changed.exception.js +17 -0
- package/src/exceptions/restore-path-changed.exception.js.map +1 -0
- package/src/exceptions/restore-path-in-the-way.exception.js +17 -0
- package/src/exceptions/restore-path-in-the-way.exception.js.map +1 -0
- package/src/exceptions/restore-path-occupied.exception.js +17 -0
- package/src/exceptions/restore-path-occupied.exception.js.map +1 -0
- package/src/exceptions/restore-step-failed.exception.js +18 -0
- package/src/exceptions/restore-step-failed.exception.js.map +1 -0
- package/src/exceptions/restore-step.exception.js +14 -0
- package/src/exceptions/restore-step.exception.js.map +1 -0
- package/src/exceptions/script-step-missing.exception.js +17 -0
- package/src/exceptions/script-step-missing.exception.js.map +1 -0
- package/src/exceptions/staged-file-missing.exception.js +17 -0
- package/src/exceptions/staged-file-missing.exception.js.map +1 -0
- package/src/exceptions/store-answers-mismatch.exception.js +19 -0
- package/src/exceptions/store-answers-mismatch.exception.js.map +1 -0
- package/src/exceptions/store-count-missing.exception.js +17 -0
- package/src/exceptions/store-count-missing.exception.js.map +1 -0
- package/src/exceptions/store-field-not-a-boolean.exception.js +17 -0
- package/src/exceptions/store-field-not-a-boolean.exception.js.map +1 -0
- package/src/exceptions/store-field-not-a-string-list.exception.js +17 -0
- package/src/exceptions/store-field-not-a-string-list.exception.js.map +1 -0
- package/src/exceptions/store-file-unreadable.exception.js +18 -0
- package/src/exceptions/store-file-unreadable.exception.js.map +1 -0
- package/src/exceptions/store-object-missing.exception.js +17 -0
- package/src/exceptions/store-object-missing.exception.js.map +1 -0
- package/src/exceptions/store-object-not-a-blob.exception.js +19 -0
- package/src/exceptions/store-object-not-a-blob.exception.js.map +1 -0
- package/src/exceptions/store.exception.js +14 -0
- package/src/exceptions/store.exception.js.map +1 -0
- package/src/exceptions/tree-line-malformed.exception.js +17 -0
- package/src/exceptions/tree-line-malformed.exception.js.map +1 -0
- package/src/exceptions/unexpected-store-object.exception.js +17 -0
- package/src/exceptions/unexpected-store-object.exception.js.map +1 -0
- package/src/exceptions/unknown-entry-kind.exception.js +17 -0
- package/src/exceptions/unknown-entry-kind.exception.js.map +1 -0
- package/src/exceptions/unknown-git-mode.exception.js +17 -0
- package/src/exceptions/unknown-git-mode.exception.js.map +1 -0
- package/src/exceptions/unknown-journal-record.exception.js +17 -0
- package/src/exceptions/unknown-journal-record.exception.js.map +1 -0
- package/src/exceptions/unknown-link-kind.exception.js +17 -0
- package/src/exceptions/unknown-link-kind.exception.js.map +1 -0
- package/src/exceptions/unsupported-store-format.exception.js +17 -0
- package/src/exceptions/unsupported-store-format.exception.js.map +1 -0
- package/src/models/byte-set.js +31 -0
- package/src/models/byte-set.js.map +1 -0
- package/src/models/checkpoint-record.js +76 -0
- package/src/models/checkpoint-record.js.map +1 -0
- package/src/models/depth-order.js +23 -0
- package/src/models/depth-order.js.map +1 -0
- package/src/models/entry-kind.js +48 -0
- package/src/models/entry-kind.js.map +1 -0
- package/src/models/finished-restore.js +18 -0
- package/src/models/finished-restore.js.map +1 -0
- package/src/models/folder-file.js +20 -0
- package/src/models/folder-file.js.map +1 -0
- package/src/models/folder-index.js +41 -0
- package/src/models/folder-index.js.map +1 -0
- package/src/models/folder-record.js +27 -0
- package/src/models/folder-record.js.map +1 -0
- package/src/models/folder-store.js +38 -0
- package/src/models/folder-store.js.map +1 -0
- package/src/models/git-build.js +18 -0
- package/src/models/git-build.js.map +1 -0
- package/src/models/git-limits.js +20 -0
- package/src/models/git-limits.js.map +1 -0
- package/src/models/housekeeping-record.js +27 -0
- package/src/models/housekeeping-record.js.map +1 -0
- package/src/models/ignore-file.js +32 -0
- package/src/models/ignore-file.js.map +1 -0
- package/src/models/ignore-pattern.js +57 -0
- package/src/models/ignore-pattern.js.map +1 -0
- package/src/models/ignore-record.js +32 -0
- package/src/models/ignore-record.js.map +1 -0
- package/src/models/ignore-rules.js +48 -0
- package/src/models/ignore-rules.js.map +1 -0
- package/src/models/import-result.js +16 -0
- package/src/models/import-result.js.map +1 -0
- package/src/models/index-entry.js +56 -0
- package/src/models/index-entry.js.map +1 -0
- package/src/models/journal-reading.js +19 -0
- package/src/models/journal-reading.js.map +1 -0
- package/src/models/journal-record-type.js +43 -0
- package/src/models/journal-record-type.js.map +1 -0
- package/src/models/journal-record.js +94 -0
- package/src/models/journal-record.js.map +1 -0
- package/src/models/link-kind.js +27 -0
- package/src/models/link-kind.js.map +1 -0
- package/src/models/link-record.js +28 -0
- package/src/models/link-record.js.map +1 -0
- package/src/models/loaded-checkpoint.js +16 -0
- package/src/models/loaded-checkpoint.js.map +1 -0
- package/src/models/newest-checkpoint.js +16 -0
- package/src/models/newest-checkpoint.js.map +1 -0
- package/src/models/no-plan.js +20 -0
- package/src/models/no-plan.js.map +1 -0
- package/src/models/object-batch.js +29 -0
- package/src/models/object-batch.js.map +1 -0
- package/src/models/object-counts.js +35 -0
- package/src/models/object-counts.js.map +1 -0
- package/src/models/pending-change.js +22 -0
- package/src/models/pending-change.js.map +1 -0
- package/src/models/planned-restore.js +22 -0
- package/src/models/planned-restore.js.map +1 -0
- package/src/models/read-failure.js +37 -0
- package/src/models/read-failure.js.map +1 -0
- package/src/models/restore-run.js +28 -0
- package/src/models/restore-run.js.map +1 -0
- package/src/models/restore-script.js +82 -0
- package/src/models/restore-script.js.map +1 -0
- package/src/models/scheduled-call.js +17 -0
- package/src/models/scheduled-call.js.map +1 -0
- package/src/models/script-step.js +72 -0
- package/src/models/script-step.js.map +1 -0
- package/src/models/side-content.js +16 -0
- package/src/models/side-content.js.map +1 -0
- package/src/models/side-entry.js +21 -0
- package/src/models/side-entry.js.map +1 -0
- package/src/models/side-file.js +19 -0
- package/src/models/side-file.js.map +1 -0
- package/src/models/side-folder.js +19 -0
- package/src/models/side-folder.js.map +1 -0
- package/src/models/side-listing.js +49 -0
- package/src/models/side-listing.js.map +1 -0
- package/src/models/staged-blob.js +20 -0
- package/src/models/staged-blob.js.map +1 -0
- package/src/models/staged-step.js +16 -0
- package/src/models/staged-step.js.map +1 -0
- package/src/models/stored-object.js +26 -0
- package/src/models/stored-object.js.map +1 -0
- package/src/models/tree-file.js +14 -0
- package/src/models/tree-file.js.map +1 -0
- package/src/models/tree-listing.js +39 -0
- package/src/models/tree-listing.js.map +1 -0
- package/src/models/unhashed-file.js +16 -0
- package/src/models/unhashed-file.js.map +1 -0
- package/src/models/walk-result.js +79 -0
- package/src/models/walk-result.js.map +1 -0
- package/src/models/walked-child.js +16 -0
- package/src/models/walked-child.js.map +1 -0
- package/src/models/walked-entry.js +31 -0
- package/src/models/walked-entry.js.map +1 -0
- package/src/models/walked-listing.js +16 -0
- package/src/models/walked-listing.js.map +1 -0
- package/src/models/wildcard-pattern.js +19 -0
- package/src/models/wildcard-pattern.js.map +1 -0
- package/src/models/write-meter.js +16 -0
- package/src/models/write-meter.js.map +1 -0
- package/src/resources.js +564 -0
- package/src/resources.js.map +1 -0
- package/src/runtime-part.js +22 -0
- package/src/runtime-part.js.map +1 -0
- package/src/services/batch-output.parser.js +65 -0
- package/src/services/batch-output.parser.js.map +1 -0
- package/src/services/blob-batch.writer.js +86 -0
- package/src/services/blob-batch.writer.js.map +1 -0
- package/src/services/blob-stager.js +41 -0
- package/src/services/blob-stager.js.map +1 -0
- package/src/services/capture-pause.js +37 -0
- package/src/services/capture-pause.js.map +1 -0
- package/src/services/case-probe.js +32 -0
- package/src/services/case-probe.js.map +1 -0
- package/src/services/change-describer.js +38 -0
- package/src/services/change-describer.js.map +1 -0
- package/src/services/checkpoint-capture.js +153 -0
- package/src/services/checkpoint-capture.js.map +1 -0
- package/src/services/checkpoint-comparer.js +37 -0
- package/src/services/checkpoint-comparer.js.map +1 -0
- package/src/services/checkpoint-file.reader.js +146 -0
- package/src/services/checkpoint-file.reader.js.map +1 -0
- package/src/services/checkpoint-id-source.js +27 -0
- package/src/services/checkpoint-id-source.js.map +1 -0
- package/src/services/checkpoint-lister.js +63 -0
- package/src/services/checkpoint-lister.js.map +1 -0
- package/src/services/checkpoints-host.js +184 -0
- package/src/services/checkpoints-host.js.map +1 -0
- package/src/services/checkpoints.service.js +10 -0
- package/src/services/checkpoints.service.js.map +1 -0
- package/src/services/clock.js +26 -0
- package/src/services/clock.js.map +1 -0
- package/src/services/command-deadline.js +34 -0
- package/src/services/command-deadline.js.map +1 -0
- package/src/services/entry.reader.js +84 -0
- package/src/services/entry.reader.js.map +1 -0
- package/src/services/failures.js +55 -0
- package/src/services/failures.js.map +1 -0
- package/src/services/fast-import-leftovers.js +35 -0
- package/src/services/fast-import-leftovers.js.map +1 -0
- package/src/services/folder-deleter.js +86 -0
- package/src/services/folder-deleter.js.map +1 -0
- package/src/services/folder-file.reader.js +78 -0
- package/src/services/folder-file.reader.js.map +1 -0
- package/src/services/folder-queue.js +27 -0
- package/src/services/folder-queue.js.map +1 -0
- package/src/services/folder-sync.js +25 -0
- package/src/services/folder-sync.js.map +1 -0
- package/src/services/folder-walker.js +123 -0
- package/src/services/folder-walker.js.map +1 -0
- package/src/services/free-space.js +30 -0
- package/src/services/free-space.js.map +1 -0
- package/src/services/git-build.locator.js +67 -0
- package/src/services/git-build.locator.js.map +1 -0
- package/src/services/git-path.js +21 -0
- package/src/services/git-path.js.map +1 -0
- package/src/services/git-process.js +127 -0
- package/src/services/git-process.js.map +1 -0
- package/src/services/git-runner.js +235 -0
- package/src/services/git-runner.js.map +1 -0
- package/src/services/housekeeping-schedule.js +77 -0
- package/src/services/housekeeping-schedule.js.map +1 -0
- package/src/services/ignore-file.reader.js +41 -0
- package/src/services/ignore-file.reader.js.map +1 -0
- package/src/services/input-writer.js +67 -0
- package/src/services/input-writer.js.map +1 -0
- package/src/services/line-diff.js +32 -0
- package/src/services/line-diff.js.map +1 -0
- package/src/services/link-probe.js +22 -0
- package/src/services/link-probe.js.map +1 -0
- package/src/services/listing-comparer.js +41 -0
- package/src/services/listing-comparer.js.map +1 -0
- package/src/services/module-activation.js +42 -0
- package/src/services/module-activation.js.map +1 -0
- package/src/services/name-decoder.js +30 -0
- package/src/services/name-decoder.js.map +1 -0
- package/src/services/object.reader.js +40 -0
- package/src/services/object.reader.js.map +1 -0
- package/src/services/path-guard.js +45 -0
- package/src/services/path-guard.js.map +1 -0
- package/src/services/plan-state.js +31 -0
- package/src/services/plan-state.js.map +1 -0
- package/src/services/relative-path.js +18 -0
- package/src/services/relative-path.js.map +1 -0
- package/src/services/repository-name.js +14 -0
- package/src/services/repository-name.js.map +1 -0
- package/src/services/restore-applier.js +175 -0
- package/src/services/restore-applier.js.map +1 -0
- package/src/services/restore-journal.js +120 -0
- package/src/services/restore-journal.js.map +1 -0
- package/src/services/restore-paths.js +130 -0
- package/src/services/restore-paths.js.map +1 -0
- package/src/services/restore-planner.js +114 -0
- package/src/services/restore-planner.js.map +1 -0
- package/src/services/restore-rollback.js +159 -0
- package/src/services/restore-rollback.js.map +1 -0
- package/src/services/restore-runner.js +221 -0
- package/src/services/restore-runner.js.map +1 -0
- package/src/services/restore-scope.js +42 -0
- package/src/services/restore-scope.js.map +1 -0
- package/src/services/side-loader.js +83 -0
- package/src/services/side-loader.js.map +1 -0
- package/src/services/storage-reader.js +80 -0
- package/src/services/storage-reader.js.map +1 -0
- package/src/services/store-file.js +54 -0
- package/src/services/store-file.js.map +1 -0
- package/src/services/store-format.js +30 -0
- package/src/services/store-format.js.map +1 -0
- package/src/services/store-housekeeping.js +66 -0
- package/src/services/store-housekeeping.js.map +1 -0
- package/src/services/store-opener.js +31 -0
- package/src/services/store-opener.js.map +1 -0
- package/src/services/store-reads.js +38 -0
- package/src/services/store-reads.js.map +1 -0
- package/src/services/text-probe.js +27 -0
- package/src/services/text-probe.js.map +1 -0
- package/src/services/tree-lister.js +20 -0
- package/src/services/tree-lister.js.map +1 -0
- package/src/services/wildcard.parser.js +152 -0
- package/src/services/wildcard.parser.js.map +1 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Writable } from "node:stream";
|
|
9
|
+
import { WriteMeter } from "../models/write-meter.js";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { Failures } from "./failures.js";
|
|
12
|
+
export class InputWriter {
|
|
13
|
+
closed;
|
|
14
|
+
stream;
|
|
15
|
+
checked = 0;
|
|
16
|
+
failure;
|
|
17
|
+
meter = null;
|
|
18
|
+
stopped = false;
|
|
19
|
+
written = 0;
|
|
20
|
+
constructor(stream) {
|
|
21
|
+
this.stream = stream;
|
|
22
|
+
this.failure = undefined;
|
|
23
|
+
this.closed = new Promise(resolve => stream.once("close", () => resolve()));
|
|
24
|
+
stream.on("error", (error) => {
|
|
25
|
+
if (!Failures.hasCode(error, Resources.closedInputCodes))
|
|
26
|
+
this.failure = error;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get isStopped() {
|
|
30
|
+
return this.stopped;
|
|
31
|
+
}
|
|
32
|
+
static discarding() {
|
|
33
|
+
return new InputWriter(new Writable({ write: (_chunk, _encoding, done) => done() }));
|
|
34
|
+
}
|
|
35
|
+
end() {
|
|
36
|
+
this.stream.end();
|
|
37
|
+
}
|
|
38
|
+
meterEvery(interval, check) {
|
|
39
|
+
this.checked = 0;
|
|
40
|
+
this.written = 0;
|
|
41
|
+
this.meter = new WriteMeter(interval, check);
|
|
42
|
+
}
|
|
43
|
+
stopMetering() {
|
|
44
|
+
this.meter = null;
|
|
45
|
+
}
|
|
46
|
+
throwIfFailed() {
|
|
47
|
+
if (this.failure !== undefined)
|
|
48
|
+
throw this.failure;
|
|
49
|
+
}
|
|
50
|
+
async writeAsync(chunk) {
|
|
51
|
+
if (this.stopped)
|
|
52
|
+
return;
|
|
53
|
+
this.throwIfFailed();
|
|
54
|
+
if (!this.stream.write(chunk))
|
|
55
|
+
await Promise.race([new Promise(resolve => this.stream.once("drain", () => resolve())), this.closed]);
|
|
56
|
+
this.throwIfFailed();
|
|
57
|
+
this.written += typeof chunk === "string" ? Buffer.byteLength(chunk) : chunk.length;
|
|
58
|
+
if (this.meter !== null && this.written - this.checked >= this.meter.interval) {
|
|
59
|
+
this.checked = this.written;
|
|
60
|
+
if (!await this.meter.check(this.written)) {
|
|
61
|
+
this.stopped = true;
|
|
62
|
+
this.meter = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=input-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;gBACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
export class LineDiff {
|
|
10
|
+
static bodyOf(output) {
|
|
11
|
+
const start = output.indexOf(Resources.hunkStart);
|
|
12
|
+
return start < 0 ? Buffer.alloc(0) : output.subarray(start + 1);
|
|
13
|
+
}
|
|
14
|
+
static cut(body, limit) {
|
|
15
|
+
return body.length <= limit ? body : body.subarray(0, body.lastIndexOf(Resources.lineFeedByte, limit - 1) + 1);
|
|
16
|
+
}
|
|
17
|
+
static ofOneSide(content, isAdded) {
|
|
18
|
+
if (content.length === 0)
|
|
19
|
+
return content;
|
|
20
|
+
const endsInLineFeed = content.at(-1) === Resources.lineFeedByte;
|
|
21
|
+
const text = content.subarray(0, endsInLineFeed ? -1 : content.length).toString(Resources.latin1Encoding);
|
|
22
|
+
const lines = text.split(Resources.lineFeed);
|
|
23
|
+
const range = Resources.formatHunkRange(lines.length);
|
|
24
|
+
const sign = isAdded ? Resources.addedSign : Resources.deletedSign;
|
|
25
|
+
return Buffer.from([
|
|
26
|
+
isAdded ? Resources.formatAddedHunk(range) : Resources.formatDeletedHunk(range),
|
|
27
|
+
...lines.map(t => `${sign}${t}${Resources.lineFeed}`),
|
|
28
|
+
endsInLineFeed ? "" : Resources.noFinalLineFeedMarker
|
|
29
|
+
].join(""), Resources.latin1Encoding);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=line-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-diff.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/line-diff.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,QAAQ;IACZ,MAAM,CAAC,MAAM,CAAC,MAAc;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,KAAa;QAC3C,OAAO,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjH,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,OAAe,EAAE,OAAgB;QACvD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YACtB,OAAO,OAAO,CAAC;QAEjB,MAAM,cAAc,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,YAAY,CAAC;QACjE,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAC1G,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC;QACnE,OAAO,MAAM,CAAC,IAAI,CAAC;YACjB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC;YAC/E,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YACrD,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,qBAAqB;SACtD,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { rm, symlink } from "node:fs/promises";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { Failures } from "./failures.js";
|
|
13
|
+
export class LinkProbe {
|
|
14
|
+
static async canCreateLinksAsync(folder) {
|
|
15
|
+
const location = path.join(folder, `${Resources.linkProbePrefix}${randomUUID()}`);
|
|
16
|
+
const created = await Failures.recoverAsync(symlink(Resources.linkProbeTarget, location, Resources.fileLinkType).then(() => true), t => Failures.hasCode(t, Resources.linkRefusedCodes), false);
|
|
17
|
+
if (created)
|
|
18
|
+
await rm(location, { force: true });
|
|
19
|
+
return created;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=link-probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link-probe.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/link-probe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,SAAS;IACb,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAc;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,eAAe,GAAG,UAAU,EAAE,EAAE,CAAC,CAAC;QAClF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,eAAe,EAAE,QAAQ,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAC/H,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,CAAC;QAC/D,IAAI,OAAO;YACT,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ChangeStatus, PathKind } from "@noldova/checkpoints.protocol";
|
|
9
|
+
import { PendingChange } from "../models/pending-change.js";
|
|
10
|
+
export class ListingComparer {
|
|
11
|
+
static compare(before, after) {
|
|
12
|
+
const paths = [...new Set([...before.paths, ...after.paths])].sort((t, u) => Buffer.compare(Buffer.from(t), Buffer.from(u)));
|
|
13
|
+
return paths.flatMap(t => {
|
|
14
|
+
const change = ListingComparer.compareAt(t, before, after);
|
|
15
|
+
return change === null ? [] : [change];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static compareAt(path, before, after) {
|
|
19
|
+
if (before.isUnderUnread(path) || after.isUnderUnread(path))
|
|
20
|
+
return null;
|
|
21
|
+
const old = before.entryOf(path);
|
|
22
|
+
const current = after.entryOf(path);
|
|
23
|
+
const isFolder = (current ?? old)?.kind === PathKind.Folder;
|
|
24
|
+
if (before.excludes(path, isFolder) || after.excludes(path, isFolder))
|
|
25
|
+
return null;
|
|
26
|
+
const unreadReason = after.unreadReasonOf(path) ?? before.unreadReasonOf(path);
|
|
27
|
+
if (unreadReason !== null)
|
|
28
|
+
return new PendingChange(path, ChangeStatus.Unknown, old, current, unreadReason);
|
|
29
|
+
if (old === null || current === null)
|
|
30
|
+
return ListingComparer.compareOneSide(path, old, current);
|
|
31
|
+
if (old.isOtherKindThan(current))
|
|
32
|
+
return new PendingChange(path, ChangeStatus.KindChanged, old, current, null);
|
|
33
|
+
return old.isSameAs(current) ? null : new PendingChange(path, ChangeStatus.Modified, old, current, null);
|
|
34
|
+
}
|
|
35
|
+
static compareOneSide(path, old, current) {
|
|
36
|
+
return old === null
|
|
37
|
+
? new PendingChange(path, ChangeStatus.Added, null, current, null)
|
|
38
|
+
: new PendingChange(path, ChangeStatus.Deleted, old, null, null);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=listing-comparer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listing-comparer.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/listing-comparer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAM5D,MAAM,OAAO,eAAe;IACnB,MAAM,CAAC,OAAO,CAAyC,MAAsB,EAAE,KAAqB;QACzG,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7H,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACvB,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAC3D,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,SAAS,CAAyC,IAAY,EAAE,MAAsB,EAAE,KAAqB;QAC1H,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC;YACzD,OAAO,IAAI,CAAC;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I,aAAa,CAAO,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;YACxE,CAAC,CAAC,IAAI,aAAa,CAAO,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { link, lstat, rename, rm } from "node:fs/promises";
|
|
9
|
+
import { CapturePausedEvent, CaptureRequest, CaptureResumedEvent, CompareRequest, DeleteFolderRequest, ListRequest, PreviewRequest, ReadRequest, RestoredEvent, RestoreHeldUpEvent, RestoreRequest, StorageRequest } from "@noldova/checkpoints.protocol";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { CheckpointsHost } from "./checkpoints-host.js";
|
|
12
|
+
import { FreeSpace } from "./free-space.js";
|
|
13
|
+
import { GitBuildLocator } from "./git-build.locator.js";
|
|
14
|
+
import { RestoreJournal } from "./restore-journal.js";
|
|
15
|
+
export class ModuleActivation {
|
|
16
|
+
static async activateAsync(context, clock) {
|
|
17
|
+
const build = await new GitBuildLocator(import.meta.dirname).locateAsync(process.platform, process.arch);
|
|
18
|
+
const restored = context.declareEvent(RestoredEvent.event);
|
|
19
|
+
const heldUp = context.declareEvent(RestoreHeldUpEvent.event);
|
|
20
|
+
const paused = context.declareEvent(CapturePausedEvent.event);
|
|
21
|
+
const resumed = context.declareEvent(CaptureResumedEvent.event);
|
|
22
|
+
const service = new CheckpointsHost(context, build, process.platform, restored, heldUp, paused, resumed, t => new RestoreJournal(t), FreeSpace.hasRoomAsync, link, FreeSpace.readAsync, rename, rm, lstat, clock);
|
|
23
|
+
context.publishService(Resources.serviceName, service);
|
|
24
|
+
context.registerMethod(CaptureRequest.method, { handleAsync: async (t) => (await service.captureAsync(CaptureRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
25
|
+
context.registerMethod(ListRequest.method, { handleAsync: async (t) => (await service.listAsync(ListRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
26
|
+
context.registerMethod(CompareRequest.method, { handleAsync: async (t) => (await service.compareAsync(CompareRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
27
|
+
context.registerMethod(PreviewRequest.method, { handleAsync: async (t) => (await service.previewRestoreAsync(PreviewRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
28
|
+
context.registerMethod(RestoreRequest.method, { handleAsync: async (t) => (await service.restoreAsync(RestoreRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
29
|
+
context.registerMethod(ReadRequest.method, { handleAsync: async (t) => (await service.readAsync(ReadRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
30
|
+
context.registerMethod(StorageRequest.method, {
|
|
31
|
+
handleAsync: async (t) => {
|
|
32
|
+
StorageRequest.fromJson(t.payload);
|
|
33
|
+
return (await service.storageAsync(t.signal)).toJson();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
context.registerMethod(DeleteFolderRequest.method, { handleAsync: async (t) => (await service.deleteFolderAsync(DeleteFolderRequest.fromJson(t.payload), t.signal)).toJson() });
|
|
37
|
+
service.startSweep();
|
|
38
|
+
service.startGitOnce();
|
|
39
|
+
return service;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=module-activation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-activation.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/module-activation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EACL,kBAAk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
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { TextDecoder } from "node:util";
|
|
9
|
+
import { UnreadPath, UnreadReason } from "@noldova/checkpoints.protocol";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { Failures } from "./failures.js";
|
|
12
|
+
import { RelativePath } from "./relative-path.js";
|
|
13
|
+
export class NameDecoder {
|
|
14
|
+
static DECODER = new TextDecoder(Resources.utf8Encoding, { fatal: true, ignoreBOM: true });
|
|
15
|
+
static decode(names, folderPath, result) {
|
|
16
|
+
const decoded = [];
|
|
17
|
+
for (const name of names) {
|
|
18
|
+
const text = NameDecoder.decodeOrNull(name);
|
|
19
|
+
if (text === null)
|
|
20
|
+
result.addUnreadPath(new UnreadPath(RelativePath.join(folderPath, name.toString(Resources.utf8Encoding)), UnreadReason.InvalidName, null));
|
|
21
|
+
else
|
|
22
|
+
decoded.push(text);
|
|
23
|
+
}
|
|
24
|
+
return decoded;
|
|
25
|
+
}
|
|
26
|
+
static decodeOrNull(name) {
|
|
27
|
+
return Failures.recover(() => NameDecoder.DECODER.decode(name), t => t instanceof TypeError, null);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=name-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-decoder.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/name-decoder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,WAAW;IACd,MAAM,CAAU,OAAO,GAAgB,IAAI,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAElH,MAAM,CAAC,MAAM,CAAC,KAAwB,EAAE,UAAkB,EAAE,MAAkB;QACnF,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,IAAI,KAAK,IAAI;gBACf,MAAM,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;;gBAE3I,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,IAAY;QACtC,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,SAAS,EAAE,IAAI,CAAC,CAAC;IACrG,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ObjectBatch } from "../models/object-batch.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { BatchOutputParser } from "./batch-output.parser.js";
|
|
11
|
+
export class ObjectReader {
|
|
12
|
+
git;
|
|
13
|
+
constructor(git) {
|
|
14
|
+
this.git = git;
|
|
15
|
+
}
|
|
16
|
+
async readAsync(store, names, keep, largest, signal) {
|
|
17
|
+
const unique = [...new Set(names)];
|
|
18
|
+
if (unique.length === 0)
|
|
19
|
+
return new ObjectBatch([], []);
|
|
20
|
+
const checked = new ObjectBatch(unique, await this.runAsync(store, Resources.catFileInfo, unique, 0, signal));
|
|
21
|
+
const wanted = unique.filter(t => checked.get(t).type !== Resources.missingType && checked.get(t).size <= largest);
|
|
22
|
+
if (wanted.length === 0)
|
|
23
|
+
return checked;
|
|
24
|
+
const read = new ObjectBatch(wanted, await this.runAsync(store, Resources.catFileContents, wanted, keep, signal));
|
|
25
|
+
const isRead = new Set(wanted);
|
|
26
|
+
return new ObjectBatch(unique, unique.map(t => isRead.has(t) ? read.get(t) : checked.get(t)));
|
|
27
|
+
}
|
|
28
|
+
async readOneAsync(store, name, keep, largest, signal) {
|
|
29
|
+
return (await this.readAsync(store, [name], keep, largest, signal)).get(name);
|
|
30
|
+
}
|
|
31
|
+
async runAsync(store, command, names, keep, signal) {
|
|
32
|
+
return await this.git.batchAsync(store, names.map(t => Resources.formatBatchCommand(command, t)).join(""), async (output) => {
|
|
33
|
+
const parser = new BatchOutputParser(keep, command === Resources.catFileContents);
|
|
34
|
+
while (parser.objects.length < names.length)
|
|
35
|
+
parser.push(await output.nextChunkAsync());
|
|
36
|
+
return parser.objects;
|
|
37
|
+
}, signal);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=object.reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.reader.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/object.reader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA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
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { RestoreFolderChangedException } from "../exceptions/restore-folder-changed.exception.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { RelativePath } from "./relative-path.js";
|
|
11
|
+
import { RestorePaths } from "./restore-paths.js";
|
|
12
|
+
export class PathGuard {
|
|
13
|
+
folder;
|
|
14
|
+
ids;
|
|
15
|
+
constructor(folder, ids) {
|
|
16
|
+
this.folder = folder;
|
|
17
|
+
this.ids = new Map(ids);
|
|
18
|
+
}
|
|
19
|
+
async checkAsync(relativePath) {
|
|
20
|
+
await this.checkFolderAsync(RelativePath.parentOf(relativePath), relativePath);
|
|
21
|
+
}
|
|
22
|
+
async checkFolderAsync(relativeFolder, changing = relativeFolder) {
|
|
23
|
+
const folders = [""];
|
|
24
|
+
for (let folder = relativeFolder; folder !== ""; folder = RelativePath.parentOf(folder))
|
|
25
|
+
folders.splice(1, 0, folder);
|
|
26
|
+
for (const folder of folders) {
|
|
27
|
+
const stats = await RestorePaths.lstatAsync(RestorePaths.locationOf(this.folder, folder));
|
|
28
|
+
if (stats === null || !RestorePaths.isFolder(stats))
|
|
29
|
+
throw new RestoreFolderChangedException(changing, folder);
|
|
30
|
+
const fileId = RestorePaths.fileIdOf(stats);
|
|
31
|
+
const known = this.ids.get(folder);
|
|
32
|
+
if (known === undefined)
|
|
33
|
+
this.ids.set(folder, fileId);
|
|
34
|
+
else if (known !== fileId)
|
|
35
|
+
throw new RestoreFolderChangedException(changing, folder);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async renewAsync(relativeFolder) {
|
|
39
|
+
for (const folder of [...this.ids.keys()])
|
|
40
|
+
if (folder === relativeFolder || folder.startsWith(`${relativeFolder}${Resources.relativePathSeparator}`))
|
|
41
|
+
this.ids.delete(folder);
|
|
42
|
+
await this.checkFolderAsync(relativeFolder);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=path-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-guard.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/path-guard.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,SAAS;IACH,MAAM,CAAS;IACf,GAAG,CAAsB;IAE1C,YAAmB,MAAc,EAAE,GAAgC;QACjE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,YAAoB;QAC1C,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;IACjF,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,cAAsB,EAAE,QAAQ,GAAW,cAAc;QACrF,MAAM,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC;QACrB,KAAK,IAAI,MAAM,GAAG,cAAc,EAAE,MAAM,KAAK,EAAE,EAAE,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;YACrF,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;YAC1F,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACjD,MAAM,IAAI,6BAA6B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,KAAK,KAAK,SAAS;gBACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;iBAC1B,IAAI,KAAK,KAAK,MAAM;gBACvB,MAAM,IAAI,6BAA6B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,cAAsB;QAC5C,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACvC,IAAI,MAAM,KAAK,cAAc,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,cAAc,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;gBACvG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { FolderFile } from "../models/folder-file.js";
|
|
10
|
+
import { SideFile } from "../models/side-file.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { RelativePath } from "./relative-path.js";
|
|
13
|
+
export class PlanState {
|
|
14
|
+
static digestOf(changes, walk) {
|
|
15
|
+
const folders = new Set([""]);
|
|
16
|
+
for (const change of changes)
|
|
17
|
+
for (let folder = RelativePath.parentOf(change.path); folder !== "" && !folders.has(folder); folder = RelativePath.parentOf(folder))
|
|
18
|
+
folders.add(folder);
|
|
19
|
+
const hash = createHash(Resources.sumAlgorithm);
|
|
20
|
+
for (const change of changes) {
|
|
21
|
+
const file = change.before;
|
|
22
|
+
const placed = file instanceof FolderFile ? file : null;
|
|
23
|
+
const fileId = placed?.fileId ?? walk.folderIds.get(change.path) ?? null;
|
|
24
|
+
hash.update(`${JSON.stringify([change.path, file?.kind.value ?? null, file instanceof SideFile ? file.objectId : null, placed?.size ?? null, fileId])}${Resources.lineFeed}`);
|
|
25
|
+
}
|
|
26
|
+
for (const folder of [...folders].sort())
|
|
27
|
+
hash.update(`${JSON.stringify([folder, walk.folderIds.get(folder) ?? null])}${Resources.lineFeed}`);
|
|
28
|
+
return hash.digest(Resources.hexEncoding);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=plan-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-state.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/plan-state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,SAAS;IACb,MAAM,CAAC,QAAQ,CAAC,OAAiC,EAAE,IAAgB;QACxE,MAAM,OAAO,GAAG,IAAI,GAAG,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AAC,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
export class RelativePath {
|
|
10
|
+
static join(folderPath, name) {
|
|
11
|
+
return folderPath === "" ? name : `${folderPath}${Resources.relativePathSeparator}${name}`;
|
|
12
|
+
}
|
|
13
|
+
static parentOf(relativePath) {
|
|
14
|
+
const end = relativePath.lastIndexOf(Resources.relativePathSeparator);
|
|
15
|
+
return end === -1 ? "" : relativePath.slice(0, end);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=relative-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-path.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/relative-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,YAAY;IAChB,MAAM,CAAC,IAAI,CAAC,UAAkB,EAAE,IAAY;QACjD,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC,qBAAqB,GAAG,IAAI,EAAE,CAAC;IAC7F,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,YAAoB;QACzC,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;QACtE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
export class RepositoryName {
|
|
10
|
+
static matches(name) {
|
|
11
|
+
return Resources.ntfsRepositoryPattern.test(name) || Resources.hfsRepositoryPattern.test(name.replace(Resources.hfsIgnoredPattern, ""));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=repository-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-name.js","sourceRoot":"","sources":["../../../../../src/noldova.checkpoints/src/services/repository-name.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,cAAc;IAClB,MAAM,CAAC,OAAO,CAAC,IAAY;QAChC,OAAO,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1I,CAAC;CACF"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { lstat, mkdir, rename, rm, rmdir } from "node:fs/promises";
|
|
9
|
+
import { CaptureMode } from "@noldova/checkpoints.protocol";
|
|
10
|
+
import { RestorePathChangedException } from "../exceptions/restore-path-changed.exception.js";
|
|
11
|
+
import { RestorePathInTheWayException } from "../exceptions/restore-path-in-the-way.exception.js";
|
|
12
|
+
import { RestoreStepException } from "../exceptions/restore-step.exception.js";
|
|
13
|
+
import { StagedFileMissingException } from "../exceptions/staged-file-missing.exception.js";
|
|
14
|
+
import { EntryKind } from "../models/entry-kind.js";
|
|
15
|
+
import { JournalRecordType } from "../models/journal-record-type.js";
|
|
16
|
+
import { JournalRecord } from "../models/journal-record.js";
|
|
17
|
+
import { WalkedEntry } from "../models/walked-entry.js";
|
|
18
|
+
import { Resources } from "../resources.js";
|
|
19
|
+
import { Failures } from "./failures.js";
|
|
20
|
+
import { FolderFileReader } from "./folder-file.reader.js";
|
|
21
|
+
import { RelativePath } from "./relative-path.js";
|
|
22
|
+
import { RestoreJournal } from "./restore-journal.js";
|
|
23
|
+
import { RestorePaths } from "./restore-paths.js";
|
|
24
|
+
export class RestoreApplier {
|
|
25
|
+
hardLinkAsync;
|
|
26
|
+
platform;
|
|
27
|
+
walker;
|
|
28
|
+
constructor(walker, platform, hardLinkAsync) {
|
|
29
|
+
this.hardLinkAsync = hardLinkAsync;
|
|
30
|
+
this.platform = platform;
|
|
31
|
+
this.walker = walker;
|
|
32
|
+
}
|
|
33
|
+
static actionsOf(script) {
|
|
34
|
+
return [
|
|
35
|
+
...script.asideOrder.map(t => JournalRecord.ofStep(JournalRecordType.Aside, t.index)),
|
|
36
|
+
...script.create.map(t => JournalRecord.ofPath(JournalRecordType.Created, t)),
|
|
37
|
+
...script.steps.filter(t => t.stage !== null).map(t => JournalRecord.ofStep(JournalRecordType.Placing, t.index)),
|
|
38
|
+
...script.remove.map(t => JournalRecord.ofPath(JournalRecordType.Removing, t))
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
async applyAsync(run, records) {
|
|
42
|
+
const actions = RestoreApplier.actionsOf(run.script);
|
|
43
|
+
let start = 0;
|
|
44
|
+
actions.forEach((t, u) => {
|
|
45
|
+
if (records.some(v => v.isSameAs(t)))
|
|
46
|
+
start = u;
|
|
47
|
+
});
|
|
48
|
+
for (const action of actions.slice(start)) {
|
|
49
|
+
const recorded = records.find(t => t.isSameAs(action)) ?? null;
|
|
50
|
+
if (action.type === JournalRecordType.Aside)
|
|
51
|
+
await this.moveAsideAsync(run, RestoreApplier.stepOf(run, action), recorded === null);
|
|
52
|
+
else if (action.type === JournalRecordType.Created)
|
|
53
|
+
await RestoreApplier.createAsync(run, action.readPath(), recorded === null);
|
|
54
|
+
else if (action.type === JournalRecordType.Placing)
|
|
55
|
+
await this.placeAsync(run, RestoreApplier.stepOf(run, action), records);
|
|
56
|
+
else
|
|
57
|
+
await RestoreApplier.removeAsync(run, action.readPath(), recorded === null);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async findChangedAsync(run) {
|
|
61
|
+
const changed = [];
|
|
62
|
+
for (const step of run.script.asideOrder) {
|
|
63
|
+
const location = run.locationOf(step.readAside());
|
|
64
|
+
const stats = await RestorePaths.lstatAsync(location);
|
|
65
|
+
if (stats === null)
|
|
66
|
+
continue;
|
|
67
|
+
if (RestorePaths.isFolder(stats)) {
|
|
68
|
+
const walk = await this.walker.walkAsync(location, CaptureMode.EveryFile, Resources.neverCancelled);
|
|
69
|
+
if (walk.repositoryPaths.length > 0)
|
|
70
|
+
return null;
|
|
71
|
+
for (const entry of walk.entries)
|
|
72
|
+
changed.push(new WalkedEntry(RelativePath.join(step.path, entry.path), entry.location, entry.kind, await lstat(entry.location, { bigint: true })));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const kind = EntryKind.ofStats(this.platform, stats);
|
|
76
|
+
if (kind !== null && !this.isAsBefore(run, step, stats))
|
|
77
|
+
changed.push(new WalkedEntry(step.path, location, kind, stats));
|
|
78
|
+
}
|
|
79
|
+
return changed;
|
|
80
|
+
}
|
|
81
|
+
static async flushAsync(run) {
|
|
82
|
+
const folders = new Set(["", run.script.staging]);
|
|
83
|
+
for (const changed of [...run.script.steps.map(t => t.path), ...run.script.create, ...run.script.remove])
|
|
84
|
+
folders.add(RelativePath.parentOf(changed));
|
|
85
|
+
for (const folder of run.script.create)
|
|
86
|
+
folders.add(folder);
|
|
87
|
+
for (const folder of folders)
|
|
88
|
+
if (RestorePaths.isFolder(await RestorePaths.lstatAsync(run.locationOf(folder))))
|
|
89
|
+
await RestoreJournal.syncFolderAsync(run.locationOf(folder));
|
|
90
|
+
}
|
|
91
|
+
static async removeAsideAsync(run) {
|
|
92
|
+
for (const step of run.script.asideOrder)
|
|
93
|
+
await RestorePaths.retryAsync(step.path, () => rm(run.locationOf(step.readAside()), { recursive: true, force: true }));
|
|
94
|
+
await RestorePaths.retryAsync(run.script.staging, () => rm(run.locationOf(run.script.staging), { recursive: true, force: true }));
|
|
95
|
+
}
|
|
96
|
+
static stepOf(run, record) {
|
|
97
|
+
return run.script.stepAt(record.readStep());
|
|
98
|
+
}
|
|
99
|
+
isAsBefore(run, step, stats) {
|
|
100
|
+
if (stats !== null && RestorePaths.isFolder(stats))
|
|
101
|
+
return run.script.folders.get(step.path) === RestorePaths.fileIdOf(stats);
|
|
102
|
+
const entry = run.index.get(step.path);
|
|
103
|
+
return stats !== null && entry !== undefined && EntryKind.ofStats(this.platform, stats) === entry.kind &&
|
|
104
|
+
Number(stats.size) === entry.size && stats.mtimeNs === entry.modified && RestorePaths.fileIdOf(stats) === entry.fileId;
|
|
105
|
+
}
|
|
106
|
+
static async holdsAsBeforeAsync(step, location, entry) {
|
|
107
|
+
const objectId = await Failures.recoverAsync(RestorePaths.retryAsync(step.path, () => FolderFileReader.objectIdOfAsync(location, entry.kind === EntryKind.Link)), t => t instanceof RestoreStepException, null);
|
|
108
|
+
return objectId === entry.objectId;
|
|
109
|
+
}
|
|
110
|
+
async moveAsideAsync(run, step, isNew) {
|
|
111
|
+
if (isNew)
|
|
112
|
+
await run.journal.appendAsync(JournalRecord.ofStep(JournalRecordType.Aside, step.index));
|
|
113
|
+
const target = run.locationOf(step.path);
|
|
114
|
+
const aside = run.locationOf(step.readAside());
|
|
115
|
+
if (await RestorePaths.lstatAsync(aside) === null) {
|
|
116
|
+
if (await RestorePaths.lstatAsync(target) === null)
|
|
117
|
+
return;
|
|
118
|
+
await run.guard.checkAsync(step.path);
|
|
119
|
+
await RestorePaths.retryAsync(step.path, () => rename(target, aside));
|
|
120
|
+
await run.guard.checkAsync(step.path);
|
|
121
|
+
}
|
|
122
|
+
const stats = await RestorePaths.lstatAsync(aside);
|
|
123
|
+
const entry = run.index.get(step.path);
|
|
124
|
+
if (!this.isAsBefore(run, step, stats) || !RestorePaths.isFolder(stats) && (entry === undefined || !await RestoreApplier.holdsAsBeforeAsync(step, aside, entry)))
|
|
125
|
+
throw new RestorePathChangedException(step.path);
|
|
126
|
+
}
|
|
127
|
+
static async createAsync(run, relativePath, isNew) {
|
|
128
|
+
if (isNew)
|
|
129
|
+
await run.journal.appendAsync(JournalRecord.ofPath(JournalRecordType.Created, relativePath));
|
|
130
|
+
const target = run.locationOf(relativePath);
|
|
131
|
+
const twin = run.script.remove.find(t => t !== relativePath && t.toLowerCase() === relativePath.toLowerCase());
|
|
132
|
+
if (twin !== undefined && await RestorePaths.isEmptyFolderAsync(run.locationOf(twin))) {
|
|
133
|
+
await run.journal.appendAsync(JournalRecord.renamed(relativePath, twin));
|
|
134
|
+
await run.guard.checkAsync(relativePath);
|
|
135
|
+
await RestorePaths.retryAsync(relativePath, () => rename(run.locationOf(twin), target));
|
|
136
|
+
await run.guard.checkAsync(relativePath);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (RestorePaths.isFolder(await RestorePaths.lstatAsync(target)))
|
|
140
|
+
return;
|
|
141
|
+
await run.guard.checkAsync(relativePath);
|
|
142
|
+
await RestorePaths.retryAsync(relativePath, () => mkdir(target));
|
|
143
|
+
await run.guard.checkFolderAsync(relativePath);
|
|
144
|
+
}
|
|
145
|
+
async placeAsync(run, step, records) {
|
|
146
|
+
const ids = RestoreApplier.placedIdsOf(records, step.index);
|
|
147
|
+
const stage = run.locationOf(step.readStage());
|
|
148
|
+
const target = run.locationOf(step.path);
|
|
149
|
+
const staged = await RestorePaths.lstatAsync(stage);
|
|
150
|
+
if (staged === null) {
|
|
151
|
+
const there = await RestorePaths.lstatAsync(target);
|
|
152
|
+
if (there !== null && ids.includes(RestorePaths.fileIdOf(there)))
|
|
153
|
+
return;
|
|
154
|
+
throw new StagedFileMissingException(step.path);
|
|
155
|
+
}
|
|
156
|
+
if (ids.length === 0)
|
|
157
|
+
await run.journal.appendAsync(JournalRecord.ofFile(JournalRecordType.Placing, step.index, RestorePaths.fileIdOf(staged)));
|
|
158
|
+
await run.guard.checkAsync(step.path);
|
|
159
|
+
await RestorePaths.placeAsync(step.path, stage, staged, target, RestorePathInTheWayException, async (copy) => await run.journal.appendAsync(JournalRecord.ofFile(JournalRecordType.Placed, step.index, RestorePaths.fileIdOf(copy))), this.hardLinkAsync, ids);
|
|
160
|
+
await run.guard.checkAsync(step.path);
|
|
161
|
+
}
|
|
162
|
+
static placedIdsOf(records, step) {
|
|
163
|
+
return records.filter(t => t.step === step && (t.type === JournalRecordType.Placing || t.type === JournalRecordType.Placed)).map(t => t.fileId);
|
|
164
|
+
}
|
|
165
|
+
static async removeAsync(run, relativePath, isNew) {
|
|
166
|
+
if (isNew)
|
|
167
|
+
await run.journal.appendAsync(JournalRecord.ofPath(JournalRecordType.Removing, relativePath));
|
|
168
|
+
const target = run.locationOf(relativePath);
|
|
169
|
+
if (!await RestorePaths.isEmptyFolderAsync(target) || !await RestorePaths.hasExactNameAsync(target))
|
|
170
|
+
return;
|
|
171
|
+
await run.guard.checkAsync(relativePath);
|
|
172
|
+
await RestorePaths.retryAsync(relativePath, () => rmdir(target));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=restore-applier.js.map
|