Skip to content

Commit 7308818

Browse files
committed
chmod: fix EROFS showing as Permission denied
1 parent 055a66b commit 7308818

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/uu/chmod/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ chmod-error-no-such-file = cannot access {$file}: No such file or directory
1010
chmod-error-preserve-root = it is dangerous to operate recursively on {$file}
1111
chmod: use --no-preserve-root to override this failsafe
1212
chmod-error-permission-denied = cannot access {$file}: Permission denied
13+
chmod-error-read-only-file-system = changing permissions of {$file}: Read-only file system
1314
chmod-error-new-permissions = {$file}: new permissions are {$actual}, not {$expected}
1415
chmod-error-missing-operand = missing operand
1516

src/uu/chmod/locales/fr-FR.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ chmod-error-no-such-file = impossible d'accéder à {$file} : Aucun fichier ou r
2222
chmod-error-preserve-root = il est dangereux d'opérer récursivement sur {$file}
2323
chmod: utiliser --no-preserve-root pour outrepasser cette protection
2424
chmod-error-permission-denied = impossible d'accéder à {$file} : Permission refusée
25+
chmod-error-read-only-file-system = modification des permissions de {$file} : Système de fichiers en lecture seule
2526
chmod-error-new-permissions = {$file} : les nouvelles permissions sont {$actual}, pas {$expected}
2627
chmod-error-missing-operand = opérande manquant
2728

src/uu/chmod/src/chmod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum ChmodError {
3535
PreserveRoot(PathBuf),
3636
#[error("{}", translate!("chmod-error-permission-denied", "file" => _0.quote()))]
3737
PermissionDenied(PathBuf),
38+
#[error("{}", translate!("chmod-error-read-only-file-system", "file" => _0.quote()))]
39+
ReadOnlyFileSystem(PathBuf),
3840
#[error("{}", translate!("chmod-error-new-permissions", "file" => _0.maybe_quote(), "actual" => _1.clone(), "expected" => _2.clone()))]
3941
NewPermissions(PathBuf, String, String),
4042
}
@@ -609,14 +611,20 @@ impl Chmoder {
609611
let (new_mode, _) = self.calculate_new_mode(current_mode, file_path.is_dir())?;
610612

611613
// Use safe traversal to change the mode
612-
if let Err(_e) = dir_fd.chmod_at(entry_name, new_mode, symlink_behavior) {
614+
if let Err(e) = dir_fd.chmod_at(entry_name, new_mode, symlink_behavior) {
613615
if self.verbose {
614616
println!(
615617
"failed to change mode of {} to {new_mode:o}",
616618
file_path.quote(),
617619
);
618620
}
619-
return Err(ChmodError::PermissionDenied(file_path.into()).into());
621+
let err = if e.kind() == std::io::ErrorKind::ReadOnlyFilesystem {
622+
ChmodError::ReadOnlyFileSystem(file_path.into())
623+
} else {
624+
ChmodError::PermissionDenied(file_path.into())
625+
};
626+
627+
return Err(err.into());
620628
}
621629

622630
// Report the change using the helper method

0 commit comments

Comments
 (0)