Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning up directories with spaces in pathnames #272

Closed
tony-travis opened this issue Jan 8, 2018 · 6 comments
Closed

cleaning up directories with spaces in pathnames #272

tony-travis opened this issue Jan 8, 2018 · 6 comments

Comments

@tony-travis
Copy link

tony-travis commented Jan 8, 2018

The "rmlint.sh" script fails when cleaning up empty folders with spaces in the pathname while removing duplicates if the "-c" option is selected, because the shell quoting "$(ls -A $DIR)" does not apply to the "$DIR" folder name.

Under Linux, the while loop can be replaced by a recursive "rmdir":

diff --git a/lib/formats/sh.sh b/lib/formats/sh.sh
index 39f3441..887b65b 100644
--- a/lib/formats/sh.sh
+++ b/lib/formats/sh.sh
@@ -235,10 +235,7 @@ remove_cmd() {
    
             if [ ! -z "$DO_DELETE_EMPTY_DIRS" ]; then
                 DIR=$(dirname "$1")
-                while [ ! "$(ls -A $DIR)" ]; do
-                    rmdir "$DIR"
-                    DIR=$(dirname "$DIR")
-                done
+                rmdir -p --ignore-fail-on-non-empty "$DIR"
             fi
         fi
     fi
@SeeSpotRun
Copy link
Collaborator

Thanks, neat solution. Although --ignore-fail-on-non-empty might not work on BSD.

@beespark
Copy link

Nested quotes around "$DIR" work inside the $() command substitution:

while [ ! "$(ls -A "$DIR")" ]; do

... and should be POSIX compliant (double-quotes can be nested with command substitution).

@tony-travis
Copy link
Author

Thanks, this is what it looks like now:

diff --git a/lib/formats/sh.sh b/lib/formats/sh.sh
index 39f3441..6a23983 100644
--- a/lib/formats/sh.sh
+++ b/lib/formats/sh.sh
@@ -235,7 +235,7 @@ remove_cmd() {

         if [ ! -z "$DO_DELETE_EMPTY_DIRS" ]; then
               DIR=$(dirname "$1")
-              while [ ! "$(ls -A $DIR)" ]; do
+              while [ ! "$(ls -A "$DIR")" ]; do
                  rmdir "$DIR"
                  DIR=$(dirname "$DIR")
               done

@SeeSpotRun
Copy link
Collaborator

Actually this was fixed some time back in develop branch but just hadn't made it to master: c9f5eaa

@loikun
Copy link

loikun commented Apr 25, 2018

Note the patch has still not made it to the master branch on april 18.
Nested quote solves the issue on removal of directory with whitespace on os X.

@sahib
Copy link
Owner

sahib commented Apr 25, 2018

@loikun: Thanks for the hint; created a new release now (v2.7.0) which includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants