Skip to content

Commit

Permalink
g3keymess: follow symlink correctly in local keystore
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Feb 26, 2025
1 parent 3d7e90f commit 2e21576
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions g3keymess/src/config/store/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,43 @@ impl KeyStoreConfig for LocalKeyStoreConfig {
.await
.map_err(|e| anyhow!("failed to read dir {}: {e}", self.dir_path.display()))?
{
if count >= BATCH_SIZE {
tokio::task::yield_now().await;
count = 0;
} else {
count += 1;
}

let path = entry.path();
// symlink is followed in `metadata()`
let meta = match entry.metadata().await {
Ok(meta) => meta,
let filetype = match entry.file_type().await {
Ok(t) => t,
Err(e) => {
warn!(" - failed to get metadata for {}: {e}", path.display());
warn!(
" - failed to get filetype for dir entry {}: {e}",
path.display()
);
continue;
}
};
if !meta.is_file() {
debug!(" - skip non-regular file {}", path.display());
continue;
}
load_add_key(&path).await;

count += 1;
if count >= BATCH_SIZE {
tokio::task::yield_now().await;
count = 0;
if filetype.is_file() {
load_add_key(&path).await;
} else if filetype.is_symlink() {
// traverse the symlink to get the real file type
match tokio::fs::metadata(&path).await {
Ok(meta) => {
if meta.is_file() {
load_add_key(&path).await;
} else {
debug!(" - skip non-regular file {}", path.display());
}
}
Err(e) => {
warn!(" - failed to get metadata for {}: {e}", path.display());
}
}
} else {
debug!(" - skip non-regular file {}", path.display());
}
}
Ok(())
Expand Down

0 comments on commit 2e21576

Please sign in to comment.