@muhkoo/cli 0.15.0-alpha.7 → 0.15.0-alpha.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muhkoo/cli",
3
- "version": "0.15.0-alpha.7",
3
+ "version": "0.15.0-alpha.8",
4
4
  "description": "Command-line interface for the Muhkoo platform — provision backends, deploy apps, and manage agents, functions, databases, and domains.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "release": "npm publish --tag alpha && npm dist-tag add @muhkoo/cli@$npm_package_version latest"
44
44
  },
45
45
  "dependencies": {
46
- "@muhkoo/connect": "0.15.0-alpha.7",
46
+ "@muhkoo/connect": "0.15.0-alpha.8",
47
47
  "snarkjs": "^0.7.0"
48
48
  },
49
49
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
package/src/lib/mount.js CHANGED
@@ -1904,10 +1904,26 @@ async function preparePass({ vfs, dir, rulesDir = dir, root, state, opts, sess,
1904
1904
  const unknown = new Set([...local.unknown, ...remote.unknown]);
1905
1905
  const files = filesOf(state);
1906
1906
  const planned = planSync({ last: files, local: local.files, remote: remote.files, unknown });
1907
- const views = { local: Object.keys(local.files).length, remote: Object.keys(remote.files).length };
1907
+ const views = {
1908
+ local: Object.keys(local.files).length,
1909
+ remote: Object.keys(remote.files).length,
1910
+ // No files and no folders here: a mount folder emptied to start
1911
+ // again, and its files come back down. What the scan left alone (the
1912
+ // mount's own .muhkoo, .DS_Store, a symlink) does not count, as no
1913
+ // pull is planned over it; a path the ignore rules hold back does.
1914
+ bare: !Object.keys(local.files).length && !local.dirs.length && !local.held.size,
1915
+ };
1908
1916
  sess.peak = Math.max(sess.peak ?? 0, Object.keys(files).length);
1909
- const { plan, held } = holdMassDeletes(planned, files, views, sess.peak);
1917
+ const { plan, held, restored } = holdMassDeletes(planned, files, views, sess.peak);
1910
1918
  for (const h of held) warnOnce(sess, `held:${h.action}:${h.count}`, ...breakerMessage(h, dir, root));
1919
+ if (restored) {
1920
+ warnOnce(
1921
+ sess,
1922
+ `restored:${restored}`,
1923
+ `${dir} holds nothing at all, so its ${restored} file${restored === 1 ? "" : "s"} come${restored === 1 ? "s" : ""} back down from ${root} rather than being deleted there.`,
1924
+ ` To delete them from your filesystem instead, use: muhkoo vfs rm -r <path>`,
1925
+ );
1926
+ }
1911
1927
  // Folders after files, by the same rule. When the breaker held file
1912
1928
  // deletes, no folder is removed either: the same pass would empty them.
1913
1929
  let dirPlan = planDirs({
@@ -1918,6 +1934,9 @@ async function preparePass({ vfs, dir, rulesDir = dir, root, state, opts, sess,
1918
1934
  fold: sess.ignoreCase ? caseFold : null,
1919
1935
  });
1920
1936
  if (held.length) dirPlan = dirPlan.filter(({ action }) => !action.startsWith("rmdir"));
1937
+ // A bare mount folder gets its folders back too, rather than taking them
1938
+ // from the remote.
1939
+ else if (views.bare) dirPlan = dirPlan.map((p) => (p.action === "rmdir-remote" ? { path: p.path, action: "mkdir-local" } : p));
1921
1940
  return {
1922
1941
  plan, dirPlan, local: local.files, remote: remote.files, sizes: remote.sizes, blobs: remote.blobs, ignores,
1923
1942
  unreadable: remote.unreadable, deferred: remote.deferred,
@@ -191,6 +191,15 @@ function coveredBy(prefixes) {
191
191
  * as they were: the next pass sees the same picture rather than "forgotten
192
192
  * files" to copy back.
193
193
  *
194
+ * One broken view is answered rather than held: a local side that holds
195
+ * nothing at all (`views.bare`: no files, no folders, nothing refused or
196
+ * unreadable) — a mount folder emptied to start again. Its remote deletes
197
+ * become pulls and `restored` counts them, so the files come back instead of
198
+ * the user deleting the state file by hand. Nothing local can be overwritten,
199
+ * as there is nothing local, and nothing remote is deleted. An empty REMOTE is
200
+ * never answered this way: there an empty view more likely means a renamed or
201
+ * missing root, and uploading everything again would put it in the wrong place.
202
+ *
194
203
  * What this is NOT: a defence against whatever can write the filesystem. It
195
204
  * catches broken views — a renamed root, an empty walk, a wiped checkout. A
196
205
  * remote party can add filler files first, so that its deletions are a
@@ -203,13 +212,16 @@ export function holdMassDeletes(plan, last, views = {}, peak = 0) {
203
212
  const tracked = Object.keys(last).length;
204
213
  const most = Math.max(tracked, peak);
205
214
  const held = [];
215
+ let restored = 0;
206
216
  for (const [action, other] of [["delete-local", "remote"], ["delete-remote", "local"]]) {
207
217
  const count = plan.filter((p) => p.action === action).length;
208
218
  if (!count) continue;
209
- if (views[other] === 0) held.push({ action, count, tracked, empty: true });
219
+ if (action === "delete-remote" && views.local === 0 && views.bare === true) restored = count;
220
+ else if (views[other] === 0) held.push({ action, count, tracked, empty: true });
210
221
  else if (count > MASS_DELETE_FLOOR && tracked - count < most / 2) held.push({ action, count, tracked });
211
222
  }
212
- if (!held.length) return { plan, held };
223
+ if (restored) plan = plan.map((p) => (p.action === "delete-remote" ? { path: p.path, action: "pull" } : p));
224
+ if (!held.length) return { plan, held, restored };
213
225
  const holding = new Set(held.map((h) => h.action));
214
- return { plan: plan.filter((p) => !holding.has(p.action)), held };
226
+ return { plan: plan.filter((p) => !holding.has(p.action)), held, restored };
215
227
  }