GNU bug report logs -
#78245
rm -d fails to remove non-empty directory
Previous Next
To reply to this bug, email your comments to 78245 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#78245
; Package
coreutils
.
(Sun, 04 May 2025 17:15:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Yannick Le Pennec <yannick.lepennec <at> live.fr>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Sun, 04 May 2025 17:15:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Dear Maintainer,
On CephFS, creating a snapshot is done suchly:
$ mkdir .snap/snapshot-name
This creates a directory which contains a view of the current directory
at the time the snapshot was created, and is therefore non-empty if the
current directory was non-empty at that time. Its contents are immutable.
Removing a snapshot is done suchly:
$ rmdir .snap/snapshot-name
This works fine even if .snap/snapshot-name is non-empty, as rmdir calls
rmdir(2) directly without trying to be smart, and the Ceph filesystem
understands what rmdir on a snapshot directory means: remove the snapshot.
One would naturally expect rm -d to behave *exactly the same* as rmdir,
but this isn't the case, because rm -d first does a getdents on the
directory, observes it is non-empty, and refuses to perform the removal.
From what I understand, this is non-compliant behavior per XCU rm 2.a. and 4.
and XSH remove():
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/rm.html
> 2. If file is of type directory, the following steps shall be taken:
> a. If neither the -R option nor the -r option is specified, but -d
> is specified, rm shall proceed with step 3 for the current file.
> 4. rm shall perform actions equivalent to the remove() function defined
> in the System Interfaces volume of POSIX.1-2024 called with a
> pathname of the current file used as the path argument.
https://pubs.opengroup.org/onlinepubs/9799919799/functions/remove.html
> If path names a directory, remove(path) shall be equivalent to rmdir(path)
In short:
rm -d .snap/snapshot-name
shall be equivalent to:
remove(".snap/snapshot-name")
which in turn shall be equivalent to:
rmdir(".snap/snapshot-name")
Moreover other coreutils rm implementations (such as uutils or voreutils)
do not exhibit this bug and correctly remove non-empty directories.
Regards,
Yannick Le Pennec
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#78245
; Package
coreutils
.
(Sun, 04 May 2025 18:02:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 78245 <at> debbugs.gnu.org (full text, mbox):
On 04/05/2025 11:35, Yannick Le Pennec wrote:
> Dear Maintainer,
>
> On CephFS, creating a snapshot is done suchly:
> $ mkdir .snap/snapshot-name
>
> This creates a directory which contains a view of the current directory
> at the time the snapshot was created, and is therefore non-empty if the
> current directory was non-empty at that time. Its contents are immutable.
>
> Removing a snapshot is done suchly:
> $ rmdir .snap/snapshot-name
>
> This works fine even if .snap/snapshot-name is non-empty, as rmdir calls
> rmdir(2) directly without trying to be smart, and the Ceph filesystem
> understands what rmdir on a snapshot directory means: remove the snapshot.
>
> One would naturally expect rm -d to behave *exactly the same* as rmdir,
> but this isn't the case, because rm -d first does a getdents on the
> directory, observes it is non-empty, and refuses to perform the removal.
>
> From what I understand, this is non-compliant behavior per XCU rm 2.a. and 4.
> and XSH remove():
>
> https://pubs.opengroup.org/onlinepubs/9799919799/utilities/rm.html
>
>> 2. If file is of type directory, the following steps shall be taken:
>> a. If neither the -R option nor the -r option is specified, but -d
>> is specified, rm shall proceed with step 3 for the current file.
>
>> 4. rm shall perform actions equivalent to the remove() function defined
>> in the System Interfaces volume of POSIX.1-2024 called with a
>> pathname of the current file used as the path argument.
>
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/remove.html
>
>> If path names a directory, remove(path) shall be equivalent to rmdir(path)
>
> In short:
> rm -d .snap/snapshot-name
> shall be equivalent to:
> remove(".snap/snapshot-name")
> which in turn shall be equivalent to:
> rmdir(".snap/snapshot-name")
>
> Moreover other coreutils rm implementations (such as uutils or voreutils)
> do not exhibit this bug and correctly remove non-empty directories.
>
> Regards,
>
> Yannick Le Pennec
For reference this was also reported at:
https://bugs.debian.org/1104300
This bug report was last modified 10 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.