cached_config: avoid parsing non-existent files multiple times

This commit is contained in:
Dietmar Maurer 2020-04-30 07:04:23 +02:00
parent ebe556d0e7
commit bd88dc4116
2 changed files with 14 additions and 6 deletions

View 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());
}
}

View 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());
}
}