sahib / rmlint

Extremely fast tool to remove duplicates and other lint from your filesystem
http://rmlint.rtfd.org
GNU General Public License v3.0
1.86k stars 128 forks source link

handle_emptydir and "-c" option with script rmlint.sh #537

Closed james-cook closed 2 years ago

james-cook commented 2 years ago

rmlint version 2.10.1 compiled on raspberry pi last year.

When I run rmlint e.g. rmlint -c sh:hardlink -S dma -s -1TB --xattr /srv/dev-disk-by-label-OMV2/shd2

It generates an rmlint.sh file with many handle_emptydir lines.

If I then run the script rmlint.sh without including the "-c" (clean up empty directories) option, the function handle_emptydirs is still called. This is perhaps in itself ok but this function does not check the "-c" (DO_DELETE_EMPTY_DIRS) flag:

handle_emptyfile() {
    print_progress_prefix
    echo "${COL_GREEN}Deleting empty file:${COL_RESET} $1"
    if [ -z "$DO_DRY_RUN" ]; then
        rm -f "$1"
    fi
}

handle_emptydir() {
    print_progress_prefix
    echo "${COL_GREEN}Deleting empty directory: ${COL_RESET}$1"
    if [ -z "$DO_DRY_RUN" ]; then
        rmdir "$1"
    fi
}

In fact DO_DELETE_EMPTY_DIRS is only ever checked inside remove_cmd() and this function is never called (?)

Coming back to rmlint after some time, I am probably missing something simple.

cebtenzzre commented 2 years ago

-c is described in the help as "Clean up empty directories while deleting duplicates" - i.e., if all files in a dir are deleted because they are duplicates, also delete the now-empty dir. To avoid counting dirs that were already empty as lint, run rmlint with something like -T "defaults -ed" (default lint types minus empty dirs).

james-cook commented 2 years ago

Ah, OK, makes sense. Thanks for the helpful information - I will close this issue now :)