btrfs-progs: fi du: skip inaccessible files

Filesystem du command fails and exits when it access file that has
permission denied. But it can continue the command except the files.
This patch prints error message just like /bin/du does and it continues
if it can.

Issue: #421
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Sidong Yang 2021-11-22 15:54:11 +00:00 committed by David Sterba
parent 9756d90ce3
commit bc2382eff9

View File

@ -403,14 +403,14 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents)
dirfd(dirstream),
shared_extents, &tot, &shr,
0);
if (ret == -ENOTTY) {
ret = 0;
continue;
} else if (ret) {
if (ret) {
errno = -ret;
fprintf(stderr,
"failed to walk dir/file: %s : %m\n",
entry->d_name);
fprintf(stderr, "cannot access: '%s:' %m\n",
entry->d_name);
if (ret == -ENOTTY || ret == -EACCES) {
ret = 0;
continue;
}
break;
}