YunoHost-Apps / nextcloud_ynh

Nextcloud package for YunoHost
https://nextcloud.com/
GNU Affero General Public License v3.0
149 stars 64 forks source link

Add -r to xargs to not miserably fail when find doesn't list any file #584

Closed alexAubin closed 1 year ago

alexAubin commented 1 year ago

Problem

cf for example https://forum.yunohost.org/t/cant-restore-nextcloud/25083/2

The datadir did not contain any file, hence find $datadir -type f | xargs -0 chmod 0640 failed because no args was provided to chmod ...

Solution

There is a -r option for xargs such that it doesn't run the command at all if there's no input. cf https://unix.stackexchange.com/questions/83709/xargs-r0-vs-xargs-0

For example:

mkdir foobar
find foobar -type f | xargs -0 chmod 0640    # will fail (no arg for chmod)
find foobar -type f | xargs -r0 chmod 0640   # will succeed (chmod aint run at all)