find(1) removes as it should a directory, but after this it complains about

Fernando Apesteguía fernando.apesteguia at gmail.com
Mon Apr 20 08:26:33 UTC 2020


El lun., 20 abr. 2020 10:16, Matthias Apitz <guru at unixarea.de> escribió:

> Hello,
>
> I've stumbled over something with find(1) which I would call a bug:
>
> $ mkdir foo
> $ find foo -type d -execdir rm -rv {} \;
> foo
> find: foo: No such file or directory
> $ ls -ld foo
> ls: foo: No such file or directory
>
> I truss'ed the find(1) and it starts as it should a child process like
> 'rm -rv foo', but when this ends correctly, find tries to open again the
> dir foo:
>
> $ truss -f -o find.tr find foo -type d -execdir rm -rv {} \;
> foo
> find: foo: No such file or directory
> $ grep foo find.tr
>  2107: fstatat(AT_FDCWD,"foo",{ mode=drwxr-xr-x
> ,inode=4099842,size=512,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
>  2108: fstatat(AT_FDCWD,"foo",{ mode=drwxr-xr-x
> ,inode=4099842,size=512,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
>  2108: access("foo",W_OK)                        = 0 (0x0)
>  2108: open("foo",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,03) = 4 (0x4)
>  2108: rmdir("foo")                              = 0 (0x0)
>  2108: write(1,"foo\n",4)                        = 4 (0x4)
>  2107: open("foo",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,03) ERR#2 'No
> such file or directory'
>  2107: write(2,"foo: No such file or directory",30) = 30 (0x1e)
>
> Is this by intention?
>

Not sure it is, but GNU find (as of findutils 4.5.12) has the same behavior.

As workaround, would -delete work fo you?

find foo -type d -delete

Cheers.


>         matthias
>
>
> --
> Matthias Apitz, ✉ guru at unixarea.de, http://www.unixarea.de/
> +49-176-38902045
> Public GnuPG key: http://www.unixarea.de/key.pub
> May, 9: Спаси́бо освободители! Thank you very much, Russian liberators!
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe at freebsd.org"
>


More information about the freebsd-questions mailing list