parrot-blackbox 2.1.1 → 2.1.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/package.json +1 -1
- package/src/storage/allocator.js +19 -3
- package/src/storage/archive.js +1 -1
- package/src/storage/rclone.js +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parrot-blackbox",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Crash-proof, multi-cloud backup & recovery automation for Parrot OS. Daily/weekly off-disk backups with automatic catch-up, smart storage across many MEGA + Google Drive accounts, Timeshift snapshot backups and one-command restore.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/cli.js",
|
package/src/storage/allocator.js
CHANGED
|
@@ -65,7 +65,11 @@ export function walkFiles(localDir) {
|
|
|
65
65
|
* will Google Drive accounts be used.
|
|
66
66
|
* 2. Within each provider tier the classic water-filling strategy applies:
|
|
67
67
|
* pick the account that results in the lowest used-percentage after
|
|
68
|
-
* placing the file
|
|
68
|
+
* placing the file. Accounts that are within ~0.5% of quota from each
|
|
69
|
+
* other are treated as equally full, and the account EARLIEST in the
|
|
70
|
+
* configured pool order wins the tie — so an all-empty pool fills in
|
|
71
|
+
* account order (mega-1, mega-2, …) instead of chasing `rclone about`
|
|
72
|
+
* usage noise.
|
|
69
73
|
*/
|
|
70
74
|
export function chooseAccount(needed, accounts) {
|
|
71
75
|
// Tier 0 = mega, Tier 1 = gdrive / everything else.
|
|
@@ -79,14 +83,26 @@ export function chooseAccount(needed, accounts) {
|
|
|
79
83
|
const candidates = eligible.filter((a) => providerTier(a) === bestTier);
|
|
80
84
|
|
|
81
85
|
// Water-fill within the chosen tier: minimise resulting used-percentage.
|
|
86
|
+
// SCORE_EPS absorbs `rclone about` usage noise — MEGA inconsistently reports
|
|
87
|
+
// a few bytes to tens-of-MiB of phantom usage on otherwise-empty accounts.
|
|
88
|
+
// As long as accounts are effectively equally full, files go onto the account
|
|
89
|
+
// EARLIEST in the configured pool order.
|
|
90
|
+
const SCORE_EPS = 0.005; // 0.5 percentage points of quota
|
|
82
91
|
let best = null;
|
|
83
92
|
let bestScore = Infinity;
|
|
84
|
-
|
|
93
|
+
let bestIdx = Infinity;
|
|
94
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
95
|
+
const acc = candidates[i];
|
|
85
96
|
const quota = acc.total || 0;
|
|
86
97
|
const score = quota ? (acc.used + needed) / quota : needed;
|
|
87
|
-
if (score < bestScore
|
|
98
|
+
if (score < bestScore - SCORE_EPS) {
|
|
88
99
|
bestScore = score;
|
|
89
100
|
best = acc;
|
|
101
|
+
bestIdx = i;
|
|
102
|
+
} else if (Math.abs(score - bestScore) <= SCORE_EPS && i < bestIdx) {
|
|
103
|
+
// Effectively a tie → the earlier account in the pool wins.
|
|
104
|
+
best = acc;
|
|
105
|
+
bestIdx = i;
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
108
|
return best;
|
package/src/storage/archive.js
CHANGED
|
@@ -150,7 +150,7 @@ export async function restoreArtifact(manifest, destDir, { onProgress } = {}) {
|
|
|
150
150
|
for (const entry of batch.entries) {
|
|
151
151
|
const target = path.join(destDir, ...entry.rel.split('/'));
|
|
152
152
|
const loc = entry.loc[0];
|
|
153
|
-
const r = await copyToFile(`${loc.remote}:${loc.path}`, target);
|
|
153
|
+
const r = await copyToFile(`${loc.remote}:${loc.path}`, target, { force: true });
|
|
154
154
|
if (!r.ok) throw new Error(`download failed for ${entry.rel}: ${r.error}`);
|
|
155
155
|
files += 1;
|
|
156
156
|
bytes += entry.size;
|
package/src/storage/rclone.js
CHANGED
|
@@ -64,9 +64,10 @@ export async function copyDir(localDir, remotePath) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/** Copy a single local file to an exact remote path. */
|
|
67
|
-
export async function copyToFile(localFile, remotePath, { ignoreExisting = false } = {}) {
|
|
67
|
+
export async function copyToFile(localFile, remotePath, { ignoreExisting = false, force = false } = {}) {
|
|
68
68
|
const args = ['copyto', localFile, remotePath];
|
|
69
69
|
if (ignoreExisting) args.push('--ignore-existing');
|
|
70
|
+
if (force) args.push('--ignore-times'); // overwrite even a "newer" destination
|
|
70
71
|
const res = await rejectFalse(args);
|
|
71
72
|
return { ok: res.exitCode === 0, exitCode: res.exitCode, error: res.stderr?.trim() };
|
|
72
73
|
}
|
|
@@ -131,7 +132,12 @@ export async function downloadBatch(remotePath, localDir, filesFromPath) {
|
|
|
131
132
|
'--files-from', filesFromPath,
|
|
132
133
|
'--transfers=16',
|
|
133
134
|
'--checkers=16',
|
|
134
|
-
'--fast-list'
|
|
135
|
+
'--fast-list',
|
|
136
|
+
// Restore MUST reproduce the artifact exactly. rclone's default skips a
|
|
137
|
+
// destination file whose mtime looks newer (exactly what fresh-install
|
|
138
|
+
// default files are), which silently leaves "conflicts" — your backed-up
|
|
139
|
+
// version never comes back. --ignore-times forces the overwrite.
|
|
140
|
+
'--ignore-times',
|
|
135
141
|
];
|
|
136
142
|
const res = await rejectFalse(args);
|
|
137
143
|
return { ok: res.exitCode === 0, exitCode: res.exitCode, error: res.stderr?.trim() };
|