aboutsummaryrefslogtreecommitdiff
path: root/modules/core/core-bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/core-bundle.js')
-rw-r--r--modules/core/core-bundle.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js
index 84d194d..d40988e 100644
--- a/modules/core/core-bundle.js
+++ b/modules/core/core-bundle.js
@@ -688,6 +688,11 @@ class VirtualFileSystem {
if (!dst || !dst.name) return false;
const node = src.dir.content[src.name];
if (!node) return false;
+ // mv a a is a no-op, not a delete (assign-then-delete on the same key used to erase it)
+ if (src.dir === dst.dir && src.name === dst.name) return true;
+ const existing = dst.dir.content[dst.name];
+ // Never clobber a directory node: its children would vanish with it (MAINT-010).
+ if (existing && existing.type === 'dir' && !existing._virtual) return false;
dst.dir.content[dst.name] = node;
delete src.dir.content[src.name];
this.saveToStorage();
@@ -703,6 +708,9 @@ class VirtualFileSystem {
if (!dst || !dst.name) return false;
const node = src.dir.content[src.name];
if (!node) return false;
+ const existing = dst.dir.content[dst.name];
+ // Never clobber a directory node: its children would vanish with it (MAINT-010).
+ if (existing && existing.type === 'dir' && !existing._virtual) return false;
dst.dir.content[dst.name] = JSON.parse(JSON.stringify(node));
this.saveToStorage();
this._emitChange(dstPath);
@@ -6482,8 +6490,11 @@ class FileSystemModule {
registerCommands() {
const self = this;
this.commands['ls'] = (args) => {
- const target = args && args.length > 0 && !args[0].startsWith('-') ? args[0] : undefined;
- const flags = (args || []).filter(a => a.startsWith('-'));
+ const argv = args || [];
+ // v4.6.104: the path may follow the flags — `ls -l /work` used to list the cwd
+ // because only argv[0] was considered (MAINT-016).
+ const flags = argv.filter(a => a.startsWith('-'));
+ const target = argv.find(a => !a.startsWith('-'));
const showLong = flags.some(f => f.includes('l'));
const showHidden = flags.some(f => f.includes('a'));
const files = this.terminal.fs.ls(target);
@@ -6618,14 +6629,24 @@ class FileSystemModule {
};
this.commands['mv'] = (args) => {
if(!args[0] || !args[1]) return this.terminal.print('Usage: mv <source> <dest>', 'warning');
- if (this.terminal.fs.mv(args[0], args[1]))
+ const fs = this.terminal.fs;
+ const d = fs._resolvePath(args[1]);
+ const dn = d && d.name ? d.dir.content[d.name] : null;
+ if (dn && dn.type === 'dir' && !dn._virtual)
+ return this.terminal.print('mv: ' + args[1] + ': is a directory — refusing to overwrite it', 'error');
+ if (fs.mv(args[0], args[1]))
this.terminal.print('Moved: ' + args[0] + ' to ' + args[1], 'success');
else
this.terminal.print('mv: ' + args[0] + ': No such file or directory', 'error');
};
this.commands['cp'] = (args) => {
if(!args[0] || !args[1]) return this.terminal.print('Usage: cp <source> <dest>', 'warning');
- if (this.terminal.fs.cp(args[0], args[1]))
+ const fs = this.terminal.fs;
+ const d = fs._resolvePath(args[1]);
+ const dn = d && d.name ? d.dir.content[d.name] : null;
+ if (dn && dn.type === 'dir' && !dn._virtual)
+ return this.terminal.print('cp: ' + args[1] + ': is a directory — refusing to overwrite it', 'error');
+ if (fs.cp(args[0], args[1]))
this.terminal.print('Copied: ' + args[0] + ' to ' + args[1], 'success');
else
this.terminal.print('cp: ' + args[0] + ': No such file or directory', 'error');