]> git.proxmox.com Git - proxmox-backup.git/commitdiff
avoid problems with missing acl.cfg and user.cfg
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 29 Apr 2020 08:40:42 +0000 (10:40 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 29 Apr 2020 08:40:42 +0000 (10:40 +0200)
src/config/acl.rs
src/config/user.rs

index b10be9c41c714f833083b4ae302829b1f803171c..7a3b314a21f71ded4b1b8bd810651e4c813149fd 100644 (file)
@@ -540,9 +540,13 @@ pub fn cached_config() -> Result<Arc<AclTree>, Error> {
             ConfigCache { data: None, last_mtime: 0, last_mtime_nsec: 0 });
     }
 
-    let stat = nix::sys::stat::stat(ACL_CFG_FILENAME)?;
+    let stat = match nix::sys::stat::stat(ACL_CFG_FILENAME) {
+        Ok(stat) => Some(stat),
+        Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => None,
+        Err(err) => bail!("unable to stat '{}' - {}", ACL_CFG_FILENAME, err),
+    };
 
-    { // limit scope
+    if let Some(stat) = stat {
         let cache = CACHED_CONFIG.read().unwrap();
         if stat.st_mtime == cache.last_mtime && stat.st_mtime_nsec == cache.last_mtime_nsec {
             if let Some(ref config) = cache.data {
@@ -555,8 +559,10 @@ pub fn cached_config() -> Result<Arc<AclTree>, Error> {
     let config = Arc::new(config);
 
     let mut cache = CACHED_CONFIG.write().unwrap();
-    cache.last_mtime = stat.st_mtime;
-    cache.last_mtime_nsec = stat.st_mtime_nsec;
+    if let Some(stat) = stat {
+        cache.last_mtime = stat.st_mtime;
+        cache.last_mtime_nsec = stat.st_mtime_nsec;
+    }
     cache.data = Some(config.clone());
 
     Ok(config)
index 813239597ed19ceb2e3a4cfa28f81ee450d157f7..514375dd62c736d04b2db2a63e911d6e76df07fa 100644 (file)
@@ -154,9 +154,13 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
             ConfigCache { data: None, last_mtime: 0, last_mtime_nsec: 0 });
     }
 
-    let stat = nix::sys::stat::stat(USER_CFG_FILENAME)?;
+    let stat = match nix::sys::stat::stat(USER_CFG_FILENAME) {
+        Ok(stat) => Some(stat),
+        Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => None,
+        Err(err) => bail!("unable to stat '{}' - {}", USER_CFG_FILENAME, err),
+    };
 
-    { // limit scope
+    if let Some(stat) = stat {
         let cache = CACHED_CONFIG.read().unwrap();
         if stat.st_mtime == cache.last_mtime && stat.st_mtime_nsec == cache.last_mtime_nsec {
             if let Some(ref config) = cache.data {
@@ -169,8 +173,10 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
     let config = Arc::new(config);
 
     let mut cache = CACHED_CONFIG.write().unwrap();
-    cache.last_mtime = stat.st_mtime;
-    cache.last_mtime_nsec = stat.st_mtime_nsec;
+    if let Some(stat) = stat {
+        cache.last_mtime = stat.st_mtime;
+        cache.last_mtime_nsec = stat.st_mtime_nsec;
+    }
     cache.data = Some(config.clone());
 
     Ok(config)