]> git.proxmox.com Git - proxmox-backup.git/commitdiff
cached_config: avoid parsing non-existent files multiple times
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 30 Apr 2020 05:04:23 +0000 (07:04 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 30 Apr 2020 05:04:23 +0000 (07:04 +0200)
src/config/acl.rs
src/config/user.rs

index c8734265b8c4afa7b801a606cf28ca2b4428af61..8b6b0148eeca0e5b30f2d9d324d1e7faa78df5de 100644 (file)
@@ -551,10 +551,14 @@ pub fn cached_config() -> Result<Arc<AclTree>, Error> {
         Err(err) => bail!("unable to stat '{}' - {}", ACL_CFG_FILENAME, err),
     };
 
-    if let Some(stat) = stat {
+    { // limit scope
         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 {
+        if let Some(ref config) = cache.data {
+            if let Some(stat) = stat {
+                if stat.st_mtime == cache.last_mtime && stat.st_mtime_nsec == cache.last_mtime_nsec {
+                    return Ok(config.clone());
+                }
+            } else if cache.last_mtime == 0 && cache.last_mtime_nsec == 0 {
                 return Ok(config.clone());
             }
         }
index 514375dd62c736d04b2db2a63e911d6e76df07fa..eab0664ad73558fb564a5a471adc1ad47e0388a2 100644 (file)
@@ -160,10 +160,14 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
         Err(err) => bail!("unable to stat '{}' - {}", USER_CFG_FILENAME, err),
     };
 
-    if let Some(stat) = stat {
+    { // limit scope
         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 {
+        if let Some(ref config) = cache.data {
+            if let Some(stat) = stat {
+                if stat.st_mtime == cache.last_mtime && stat.st_mtime_nsec == cache.last_mtime_nsec {
+                    return Ok(config.clone());
+                }
+            } else if cache.last_mtime == 0 && cache.last_mtime_nsec == 0 {
                 return Ok(config.clone());
             }
         }