1
1

Backport --(enable|disable)-(shell|delete|refresh) from 2.x

Only remaining options missing from this C implementation are
--graph-style (sounds doable, but pretty low priority) and
--shared-column (unlikely to happen).
Этот коммит содержится в:
Yorhel 2022-11-30 11:40:54 +01:00
родитель 49e4b061a5
Коммит 6dd159d489
4 изменённых файлов: 53 добавлений и 32 удалений

Просмотреть файл

@ -167,22 +167,29 @@ decreased to once every 2 seconds with C<-q> or C<--slow-ui-updates>. This
feature can be used to save bandwidth over remote connections. This option has
no effect when C<-0> is used.
=item B<--enable-shell>, B<--disable-shell>
Enable or disable shell spawning from the browser. This feature is enabled by
default when scanning a live directory and disabled when importing from file.
=item B<--enable-delete>, B<--disable-delete>
Enable or disable the built-in file deletion feature. This feature is enabled
by default when scanning a live directory and disabled when importing from
file. Explicitly disabling the deletion feature can work as a safeguard to
prevent accidental data loss.
=item B<--enable-refresh>, B<--disable-refresh>
Enable or disable directory refreshing from the browser. This feature is
enabled by default when scanning a live directory and disabled when importing
from file.
=item B<-r>
Read-only mode. This will disable the built-in file deletion feature. This
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 B<-rr>
In addition to C<-r>, this will also disable the shell spawning feature of the
file browser.
Read-only mode. When given once, this is an alias for C<--disable-delete>, when
given twice it will also add C<--disable-shell>, thus ensuring that there is no
way to modify the file system from within ncdu.
=item B<--si>, B<--no-si>
@ -272,6 +279,9 @@ starting with C<#> are ignored. Example configuration file:
# Always enable extended mode
-e
# Disable file deletion
--disable-delete
# Exclude .git directories
--exclude .git

Просмотреть файл

@ -272,7 +272,7 @@ void browse_draw(void) {
addstrc(UIC_HD, " for help");
if(dir_import_active)
mvaddstr(0, wincols-10, "[imported]");
else if(read_only)
else if(!can_delete)
mvaddstr(0, wincols-11, "[read-only]");
/* second line - the path */
@ -323,7 +323,7 @@ void browse_draw(void) {
if(message) {
nccreate(6, 60, "Message");
ncaddstr(2, 2, message);
ncaddstr(4, 34, "Press any key to continue");
ncaddstr(4, 33, "Press any key to continue");
}
/* draw information window */
@ -488,8 +488,8 @@ int browse_key(int ch) {
/* and other stuff */
case 'r':
if(dir_import_active) {
message = "Directory imported from file, won't refresh.";
if(!can_refresh) {
message = "Directory refresh feature disabled.";
break;
}
if(dirlist_par) {
@ -527,14 +527,12 @@ int browse_key(int ch) {
info_show = 0;
break;
case 'd':
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;
}
if(sel == NULL || sel == dirlist_parent)
break;
if(!can_delete) {
message = "Deletion feature disabled.";
break;
}
info_show = 0;
if((t = dirlist_get(1)) == sel)
if((t = dirlist_get(-1)) == sel || t == dirlist_parent)
@ -542,10 +540,8 @@ int browse_key(int ch) {
delete_init(sel, t);
break;
case 'b':
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.";
if(!can_shell) {
message = "Shell feature disabled.";
break;
}
shell_init();

Просмотреть файл

@ -95,8 +95,10 @@ struct dir_ext {
/* program state */
extern int pstate;
/* read-only flag, 1+ = disable deletion, 2+ = also disable shell */
extern int read_only;
/* enabled features */
extern int can_delete;
extern int can_shell;
extern int can_refresh;
/* minimum screen update interval when calculating, in ms */
extern long update_delay;
/* filter directories with CACHEDIR.TAG */

Просмотреть файл

@ -35,7 +35,9 @@
int pstate;
int read_only = 0;
int can_delete = -1;
int can_shell = -1;
int can_refresh = -1;
long update_delay = 100;
int cachedir_tags = 0;
int extended_info = 0;
@ -197,7 +199,14 @@ static int arg_option(void) {
else if(OPT("--cross-file-system")) dir_scan_smfs = 0;
else if(OPT("-e") || OPT("--extended")) extended_info = 1;
else if(OPT("--no-extended")) extended_info = 0;
else if(OPT("-r")) read_only++;
else if(OPT("-r") && !can_delete) can_shell = 0;
else if(OPT("-r")) can_delete = 0;
else if(OPT("--enable-shell")) can_shell = 1;
else if(OPT("--disable-shell")) can_shell = 0;
else if(OPT("--enable-delete")) can_delete = 1;
else if(OPT("--disable-delete")) can_delete = 0;
else if(OPT("--enable-refresh")) can_refresh = 1;
else if(OPT("--disable-refresh")) can_refresh = 0;
else if(OPT("--show-hidden")) dirlist_hidden = 0;
else if(OPT("--hide-hidden")) dirlist_hidden = 1;
else if(OPT("--show-itemcount")) show_items = 1;
@ -406,6 +415,10 @@ static void argv_parse(int argc, char **argv) {
* feedback when exporting to stdout. */
if(dir_ui == -1)
dir_ui = export && strcmp(export, "-") == 0 ? 0 : export ? 1 : 2;
if(can_delete == -1) can_delete = import ? 0 : 1;
if(can_shell == -1) can_shell = import ? 0 : 1;
if(can_refresh == -1) can_refresh = import ? 0 : 1;
}