1
0
Fork 0

fix trash-put when missing trash directories

This commit is contained in:
Luca Bilke 2024-01-13 13:57:46 +01:00
parent efe6f1f90e
commit 727af2a5f3
1 changed files with 10 additions and 9 deletions

View File

@ -35,7 +35,7 @@ sub trash_dirs ($file_fs_root) {
}
sub target_file_name ( $file_name, $trash_file_path ) {
opendir( my $dir, "$trash_file_path" ) or die "$!\n";
opendir( my $dir, "$trash_file_path" ) or die "$!";
my $existing_suffix_nums =
map( ( $_ =~ /^${file_name}\.~(\d)~/ ), readdir $dir );
my $suffix_num = max($existing_suffix_nums) + 1;
@ -46,20 +46,22 @@ sub target_file_name ( $file_name, $trash_file_path ) {
}
sub write_file ( $file_path, $contents ) {
open( FH, '>', $file_path ) or die "$!\n";
open( FH, '>', $file_path ) or die "$!";
print FH $contents;
}
# NOTE: Execution starts here
if ( $#ARGV + 1 != 1 ) {
die "Bad Arguments\n";
die "Bad Arguments";
}
stat $ARGV[0] or die "$!\n";
stat $ARGV[0] or die "$!";
my ( $file_name, $file_src, $file_fs_root ) = file_info( $ARGV[0] );
my ( $trash_info_path, $trash_file_path ) = trash_dirs($file_fs_root);
make_path( $trash_info_path, $trash_file_path ) or die "$!";
my $target_name = target_file_name( $file_name, $trash_file_path );
chomp( my $deletion_time = `date -u +%Y%m%dUTC%T` );
@ -69,6 +71,5 @@ Path=$file_src
DeletionDate=$deletion_time
EOF
make_path( $trash_info_path, $trash_file_path );
rename( $file_src, "$trash_file_path/$target_name" ) or die "$!\n";
write_file( "$trash_info_path/$target_name", $info_contents ) or die "$!\n";
rename( $file_src, "$trash_file_path/$target_name" ) or die "$!";
write_file( "$trash_info_path/$target_name", $info_contents ) or die "$!";