Paul Ruane wrote:
> If I have the following directory structure:
>
>> mkdir -p a/a1 a/a2
>
> If I then remove these empty directories using the --parents option,
> rmdir reports an error:
>
>> rmdir --parents a/a1 a/a2
> rmdir: failed to remove directory `a': Directory not empty
>
> Despite the error, the command completes with the desired result.
>
> It is pretty obvious what is happening: rmdir is treating each
> argument in isolation:
>
> 1. argument 'a/a1'
>     1.1. attempt to remove 'a/a1': success
>     1.2. attempt to remove 'a': error as directory not empty
> 2. argument 'a/a2'
>     2.1. attempt to remove 'a/a2': success
>     2.2. attempt to remove 'a': success
>
> However I would expect the parent directory removal to happen after
> the arguments are removed, which would result in a better user
> experience. For example:
>
> 1. argument 'a/a1'
>     1.1. attempt to remove 'a/a1': success
>     1.2. remember parent 'a'
> 2. argument 'a/a2'
>     2.1. attempt to remove 'a/a2': success
>     2.2. parent 'a' already in set of parents
> 3. remembered parent 'a'
>     3.1. remove parent 'a': success

Thanks for the suggestion.
However, while in your case it appears to require little work,
in general, it is probably not worth the added complexity.

Imagine a command like this:

  rmdir --parents a/b ... many-other-arguments ... a/c

That means we'd have to defer removing a/ until the last argument,
and to know that we need to handle this unusual case, we'd have to
inspect each of the intervening arguments.

Now, consider this:

  rmdir --parents a/b b/x ... many-other-arguments ... a/c b/y

Now we have to search for both a/ and b/-prefixed arguments.
And what if we have this?

  rmdir --parents a/b/c ... many-other-arguments ... a/b/d

Now we have to defer not just the removal of a/, but also the removal of a/b/.

Instead, if you really want to avoid that diagnostic when using --parents,
how about runing one rmdir process per argument when two or more share a
leading directory?



Reply via email to