From efbd37467881aabc37359e62c5a772eeba72f799 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Wed, 12 Apr 2017 14:53:11 +0200 Subject: [PATCH] No longer failing restore if setting file attributes fails --- CHANGELOG.md | 1 + src/repository/metadata.rs | 39 ++++++++++++-------------------------- src/util/fs.rs | 3 ++- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8033c8a..15dce13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project follows [semantic versioning](http://semver.org). ### UNRELEASED - [added] Added CHANGELOG - [added] Locking local repository to avoid index corruption +- [added] Storing user/group names in backup - [modified] No longer trying to upload by rename - [fixed] Creating empty bundle cache on init to avoid warnings - [fixed] Calling sodiumoxide::init for faster algorithms and thread safety (not needed) diff --git a/src/repository/metadata.rs b/src/repository/metadata.rs index e61ce7a..72c6621 100644 --- a/src/repository/metadata.rs +++ b/src/repository/metadata.rs @@ -39,26 +39,6 @@ quick_error!{ description("Failed to create entity") display("Inode error: failed to create entity {:?}\n\tcaused by: {}", path, err) } - SetPermissions(err: io::Error, path: PathBuf, mode: u32) { - cause(err) - description("Failed to set permissions") - display("Inode error: failed to set permissions to {:3o} on {:?}\n\tcaused by: {}", mode, path, err) - } - SetTimes(err: io::Error, path: PathBuf) { - cause(err) - description("Failed to set file times") - display("Inode error: failed to set file times on {:?}\n\tcaused by: {}", path, err) - } - SetOwnership(err: io::Error, path: PathBuf) { - cause(err) - description("Failed to set file ownership") - display("Inode error: failed to set file ownership on {:?}\n\tcaused by: {}", path, err) - } - SetXattr(err: io::Error, path: PathBuf) { - cause(err) - description("Failed to set xattr") - display("Inode error: failed to set xattr on {:?}\n\tcaused by: {}", path, err) - } Integrity(reason: &'static str) { description("Integrity error") display("Inode error: inode integrity error: {}", reason) @@ -225,21 +205,26 @@ impl Inode { } } let time = FileTime::from_seconds_since_1970(self.timestamp as u64, 0); - try!(filetime::set_file_times(&full_path, time, time).map_err(|e| InodeError::SetTimes(e, full_path.clone()))); + if let Err(err) = filetime::set_file_times(&full_path, time, time) { + warn!("Failed to set file time on {:?}: {}", full_path, err); + } if !self.xattrs.is_empty() { if xattr::SUPPORTED_PLATFORM { for (name, data) in &self.xattrs { - try!(xattr::set(&full_path, name, data).map_err(|e| InodeError::SetXattr(e, full_path.clone()))) + if let Err(err) = xattr::set(&full_path, name, data) { + warn!("Failed to set xattr {} on {:?}: {}", name, full_path, err); + } } } else { warn!("Not setting xattr on {:?}", full_path); } } - try!(fs::set_permissions( - &full_path, - Permissions::from_mode(self.mode) - ).map_err(|e| InodeError::SetPermissions(e, full_path.clone(), self.mode))); - try!(chown(&full_path, self.user, self.group).map_err(|e| InodeError::SetOwnership(e, full_path.clone()))); + if let Err(err) = fs::set_permissions(&full_path, Permissions::from_mode(self.mode)) { + warn!("Failed to set permissions {:o} on {:?}: {}", self.mode, full_path, err); + } + if let Err(err) = chown(&full_path, self.user, self.group) { + warn!("Failed to set user {} and group {} on {:?}: {}", self.user, self.group, full_path, err); + } Ok(file) } diff --git a/src/util/fs.rs b/src/util/fs.rs index c9d8774..630dae1 100644 --- a/src/util/fs.rs +++ b/src/util/fs.rs @@ -12,7 +12,8 @@ mod linux { let result = unsafe { libc::lchown((&path).as_ptr(), uid, gid) }; match result { 0 => Ok(()), - err => Err(io::Error::from_raw_os_error(err)) + -1 => Err(io::Error::last_os_error()), + _ => unreachable!() } } }