From a2acae4f2265f6d71ccc28b0d4560f2c205bafcb Mon Sep 17 00:00:00 2001 From: Kirpal Grewal Date: Thu, 12 Dec 2024 13:51:26 +0000 Subject: [PATCH] rename alt and add processing for old paths --- nativelink-store/src/filesystem_store.rs | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/nativelink-store/src/filesystem_store.rs b/nativelink-store/src/filesystem_store.rs index cb7ec6197..dd72c971c 100644 --- a/nativelink-store/src/filesystem_store.rs +++ b/nativelink-store/src/filesystem_store.rs @@ -446,7 +446,7 @@ async fn add_files_to_cache( block_size: u64, ) -> Result<(), Error> { #[expect(clippy::too_many_arguments)] - async fn process_entry_alt( + async fn process_entry( evicting_map: &EvictingMap, SystemTime>, file_name: &str, file_type: FileType, @@ -528,6 +528,32 @@ async fn add_files_to_cache( .await } + // Move old digest files to the digest folder. + let (_permit, dir_handle) = fs::read_dir(format!("{}/", shared_context.content_path)) + .await + .err_tip(|| "Failed opening content directory for iterating in filesystem store")? + .into_inner(); + + let mut read_dir_stream = ReadDirStream::new(dir_handle); + + while let Some(entry) = read_dir_stream.next().await { + let entry = entry?; + let path = entry.path(); + + if path.is_file() { + let file_name = path.file_name().unwrap(); + + let new_path = format!( + "{}/{}/{:?}", + shared_context.content_path, DIGEST_FOLDER, file_name + ); + + fs::rename(&path, &new_path) + .await + .err_tip(|| format!("Failed to move file {path:?} to {new_path:?}"))?; + } + } + let mut file_infos: Vec<(String, FileType, SystemTime, u64)> = read_files(FileType::String, shared_context).await?; @@ -538,7 +564,7 @@ async fn add_files_to_cache( file_infos.sort_by(|a, b| a.2.cmp(&b.2)); for (file_name, file_type, atime, data_size) in file_infos { - let result = process_entry_alt( + let result = process_entry( evicting_map, &file_name, file_type,