Skip to content

chmod: incorrect error handling when multiple files are processed #9790

Description

@sylvestre

Component

chmod

Description

In Chmoder::chmod, the return code is directly set as

            if self.recursive {
                r = self.walk_dir_with_context(file, true);
            } else {
                r = self.chmod_file(file).and(r);
            }

This means that if multiple files are being processed, the return code will be determined solely by the last file processed. If the last file is successful, the return code will be 0, even if previous files encountered errors. This will affect scripts that rely on the exit code to determine if all operations were successful.

Test / Reproduction Steps

core_sbx$ mkdir chmod-bug/user chmod-bug/root
core_sbx$ touch chmod-bug/user/user_owned chmod-bug/root/root_owned
core_sbx$ sudo chown root:root chmod-bug/root/root_owned
core_sbx$ chmod -R 0755 chmod-bug/root chmod-bug/user; echo "gnu ret=$?"
chmod: changing permissions of 'chmod-bug/root/root_owned': Operation not permitted
gnu ret=1
core_sbx$ ../target/release/chmod -R 0755 chmod-bug/root chmod-bug/user; echo "uutils ret=$?"
../target/release/chmod: Operation not permitted (os error 1)
uutils ret=0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions