Skip to content

Commit

Permalink
Add ability to hide dotfiles in File Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Sep 28, 2023
1 parent 0ea5c6d commit a855625
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
25 changes: 21 additions & 4 deletions extensions/file-manager/file-manager-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ sub get_user_config
}
}

sub get_user_config_showhiddenfiles
{
return get_user_config('config_portable_module_filemanager_show_dot_files') ne 'false';
}

sub kill_previous
{
my $pid = tokenize($_[0]);
Expand Down Expand Up @@ -270,6 +275,7 @@ sub test_all_items_query
sub get_entries_list
{
my @entries_list;
my $show_dot_files = get_user_config_showhiddenfiles();
if (test_all_items_query()) {
if ($in{'query'}) {
@entries_list = exec_search('list');
Expand All @@ -279,7 +285,7 @@ sub get_entries_list
wanted => sub {
my $found = $File::Find::name;
$found =~ s/^\Q$cwd\/\E//g;
if ($_ ne '.' && $_ ne '..' && $found !~ /\//) {
if ($_ ne '.' && $_ ne '..' && $found !~ /\// && ($show_dot_files || ($_ !~ /^\./ && $found !~ /\/\./))) {
push(@entries_list, $found);
}
},
Expand Down Expand Up @@ -443,6 +449,8 @@ sub exec_search
my @results;
my @excludes;

my $show_dot_files = get_user_config_showhiddenfiles();

my @results_cached = cache_search($fsid);
if (@results_cached) {
return @results_cached;
Expand Down Expand Up @@ -606,7 +614,9 @@ sub exec_search
}
}
if (!$extra_exclude && (!$exclude || (@excludes && !$excluded))) {
push(@results, $found);
if ($show_dot_files || ($_ !~ /^\./ && $found !~ /\/\./)) {
push(@results, $found);
}
}
}
}
Expand Down Expand Up @@ -676,6 +686,8 @@ sub print_content
$path =~ s/[\/]+/\//g;
return $path;
};

my $show_dot_files = get_user_config_showhiddenfiles();

# In case of search trim the list accordingly
if ($query) {
Expand All @@ -685,7 +697,8 @@ sub print_content
print_error("$text{'theme_xhred_global_error'}: [tt]`$cwd`[/tt]- $!.");
exit;
}
@list = grep {$_ ne '.' && $_ ne '..'} readdir(DIR);

@list = grep {$_ ne '.' && $_ ne '..' && ($show_dot_files || ($_ !~ /^\./ && $_ !~ /\/\./))} readdir(DIR);
closedir(DIR);
}

Expand Down Expand Up @@ -1113,6 +1126,8 @@ sub get_tree
my @af = length($p) ? ($p) : @ap;
my $fu = scalar(@af) == 1;

my $show_dot_files = get_user_config_showhiddenfiles();

# Check the queried path is allowed in the first place
if (length($p)) {
return \@r if (grep {$_ =~ /^\Q$p\E/} @ap);
Expand All @@ -1128,7 +1143,9 @@ sub get_tree
my $pp = ($fu && $afic ne '/') ? $afic : undef;
my $c = $r{$td} =
{ key => html_escape("$pp/$td"), title => (defined($cd) ? html_escape($cd) : html_escape($td)), link => $ltd };
defined $pd ? (push @{ $r{$pd}{'children'} }, $c) : (push @r, $c);
if ($show_dot_files || ($td !~/^\./ && $td !~/\/\./ && $cd !~/^\./ && $cd !~/\/\./)) {
defined $pd ? (push @{ $r{$pd}{'children'} }, $c) : (push @r, $c);
}
};

my $dc = $td =~ tr[/][];
Expand Down
1 change: 1 addition & 0 deletions modules/filemin/config.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ per_page=30
config_portable_module_filemanager_default_sort=0
config_portable_module_filemanager_records_for_server_pagination=1000
config_portable_module_filemanager_move_to_trash=false
config_portable_module_filemanager_show_dot_files=true

config_portable_module_filemanager_hide_tree_view=false
config_portable_module_filemanager_tree_expand_search=true
Expand Down
1 change: 1 addition & 0 deletions modules/filemin/config.info
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ config_portable_module_filemanager_force_tar=Force <code>tar</code> command&#44;
config_portable_module_filemanager_files_safe_mode=Do not overwrite existing files upon operations,1,true-Yes,false-No
config_portable_module_filemanager_switch_users=Automatically set owner and group equivalent to user home on file operations,1,true-Yes,false-No
config_portable_module_filemanager_hide_actions=Hide column containing action icons,1,true-Yes,false-No
config_portable_module_filemanager_show_dot_files=Show all hidden files,1,true-Yes,false-No
1 change: 1 addition & 0 deletions unauthenticated/js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var
config_portable_module_filemanager_view_limit = 512000,
config_portable_module_filemanager_checksum_limit = 1024000,
config_portable_module_filemanager_move_to_trash = false,
config_portable_module_filemanager_show_dot_files = true,

// Locale defaults
config_portable_theme_locale_format_full = 'LLLL',
Expand Down

0 comments on commit a855625

Please sign in to comment.