summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2017-01-06 18:35:30 +0100
committerYorhel <git@yorhel.nl>2017-01-06 18:35:30 +0100
commit936a9446a8853cf87d3bfd6e3a998e54825e85de (patch)
tree8e20be370ac1c9f067e6221cb09835bd575f1789
parente4f211db68dc6155f7df44547cf99dab5db6b16d (diff)
Add -rr option to disable shell spawning
Fixes https://dev.yorhel.nl/ncdu/bug/94
-rw-r--r--doc/ncdu.pod14
-rw-r--r--src/browser.c10
-rw-r--r--src/global.h2
-rw-r--r--src/main.c2
4 files changed, 20 insertions, 8 deletions
diff --git a/doc/ncdu.pod b/doc/ncdu.pod
index f752232..861271a 100644
--- a/doc/ncdu.pod
+++ b/doc/ncdu.pod
@@ -35,8 +35,8 @@ I<FILE> is equivalent to C<->, the file is read from standard input.
For the sake of preventing a screw-up, the current version of ncdu will assume
that the directory information in the imported file does not represent the
-filesystem on which the file is being imported. That is, the refresh and file
-deletion options in the browser will be disabled.
+filesystem on which the file is being imported. That is, the refresh, file
+deletion and shell spawning options in the browser will be disabled.
=item I<dir>
@@ -97,6 +97,16 @@ option has no effect when C<-o> is used, because there will not be a browser
interface in that case. It has no effect when C<-f> is used, either, because
the deletion feature is disabled in that case anyway.
+WARNING: This option will only prevent deletion through the file browser. It is
+still possible to spawn a shell from ncdu and delete or modify files from
+there. To disable that feature as well, pass the C<-r> option twice (see
+C<-rr>).
+
+=item -rr
+
+In addition to C<-r>, this will also disable the shell spawning feature of the
+file browser.
+
=item --si
List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as
diff --git a/src/browser.c b/src/browser.c
index e26683b..38a8afc 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -417,8 +417,8 @@ int browse_key(int ch) {
info_show = 0;
break;
case 'd':
- if(read_only || dir_import_active) {
- message = read_only
+ if(read_only >= 1 || dir_import_active) {
+ message = read_only >= 1
? "File deletion disabled in read-only mode."
: "File deletion not available for imported directories.";
break;
@@ -432,8 +432,10 @@ int browse_key(int ch) {
delete_init(sel, t);
break;
case 'b':
- if(dir_import_active) {
- message = "Shell feature not available for imported directories.";
+ if(read_only >= 2 || dir_import_active) {
+ message = read_only >= 2
+ ? "Shell feature disabled in read-only mode."
+ : "Shell feature not available for imported directories.";
break;
}
shell_init();
diff --git a/src/global.h b/src/global.h
index e2c0b76..4cd02e1 100644
--- a/src/global.h
+++ b/src/global.h
@@ -84,7 +84,7 @@ struct dir {
/* program state */
extern int pstate;
-/* read-only flag */
+/* read-only flag, 1+ = disable deletion, 2+ = also disable shell */
extern int read_only;
/* minimum screen update interval when calculating, in ms */
extern long update_delay;
diff --git a/src/main.c b/src/main.c
index a5ad2f6..7d361cc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -162,7 +162,7 @@ static void argv_parse(int argc, char **argv) {
printf("ncdu %s\n", PACKAGE_VERSION);
exit(0);
case 'x': dir_scan_smfs = 1; break;
- case 'r': read_only = 1; break;
+ case 'r': read_only++; break;
case 's': si = 1; break;
case 'o': export = val; break;
case 'f': import = val; break;