TritonDataCenter / node-manta

Node.js SDK for Manta
75 stars 54 forks source link

Want option to confim removal of files for `mrm` #335

Closed jordanhendricks closed 6 years ago

jordanhendricks commented 7 years ago

Having accidentally removed some files in Manta (via improper editing of previous commands), I think it would be nice for the to optionally check that the file you are trying to remove from Manta is correct.

That is, I want something analogous to the behavior of rm -i:

$ ls
not-important.txt  very-important.txt

$ rm -i very-important.txt 
 remove very-important.txt? n

$ rm -i not-important.txt 
remove not-important.txt? y

$ ls
very-important.txt

The -i option for mrm is already claimed, so the confirmation option for mrm would need to be a different flag from rm.

bahamas10 commented 6 years ago

https://cr.joyent.us/#/c/4714/

mrmdir

$ ./bin/mmkdir ~~/stor/test-dir{1..5}
$ ./bin/mls
test-dir1/
test-dir2/
test-dir3/
test-dir4/
test-dir5/
$ ./bin/mrmdir -I ~~/stor/test-dir{1..5}
remove directory `/dave/stor/test-dir1` [y/N]?: n
remove directory `/dave/stor/test-dir2` [y/N]?: 
remove directory `/dave/stor/test-dir3` [y/N]?: foo
remove directory `/dave/stor/test-dir4` [y/N]?: y
remove directory `/dave/stor/test-dir5` [y/N]?: nope
$ ./bin/mls
test-dir1/
test-dir2/
test-dir3/
test-dir5/

mrm

$ touch empty
$ for f in ~~/stor/test-object{1..5}; do mput -f empty "$f"; done
$ mls
test-object1
test-object2
test-object3
test-object4
test-object5
$ ./bin/mrm -I ~~/stor/test-object{1..5}
remove object `/dave/stor/test-object1` [y/N]?: n
remove object `/dave/stor/test-object2` [y/N]?: 
remove object `/dave/stor/test-object3` [y/N]?: foo
remove object `/dave/stor/test-object4` [y/N]?: y
remove object `/dave/stor/test-object5` [y/N]?: nope
$ mls
test-object1
test-object2
test-object3
test-object5

Tests created for mrm and mrmdir

$ ./node_modules/.bin/nodeunit test/mrmdir.test.js 

mrmdir.test.js
✔ setup: create test tree at /dave/stor/node-manta-test-mrmdir-01d47615
✔ mrmdir (no arguments)
✔ mrmdir -I fails without tty
✔ mrmdir 1 directory
✔ remove remaining directories
✔ ensure test tree is empty
✔ cleanup: rm test tree /dave/stor/node-manta-test-mrmdir-01d47615

OK: 11 assertions (18414ms)
$ ./node_modules/.bin/nodeunit test/mrm.test.js 

mrm.test.js
✔ setup: create test tree at /dave/stor/node-manta-test-mrm-91cf20a6
✔ mrm (no arguments)
✔ mrm -I fails without tty
✔ mrm 1 directory
✔ remove remaining directories
✔ mrm 1 object
✔ remove remaining objects
✔ ensure test tree is empty
✔ cleanup: rm test tree /dave/stor/node-manta-test-mrm-91cf20a6

OK: 15 assertions (41372ms)