From 1286db23fd14bbaef2f98f8cda9e5576605277f6 Mon Sep 17 00:00:00 2001 From: Till Wegmueller Date: Sun, 27 Jul 2025 16:27:22 +0200 Subject: [PATCH] Implement two-level file path hierarchy in `pkg5_import.rs` and remove redundant e2e tests - Introduce a two-level directory structure for file paths (`xx/yy/hash`) in `pkg5_import.rs` for improved scalability, with fallback to the old structure for compatibility. - Remove outdated end-to-end tests for `pkg5` imports, reducing redundancy and streamlining test coverage. --- pkg6repo/src/e2e_tests.rs | 122 +----------------------------------- pkg6repo/src/pkg5_import.rs | 16 ++++- 2 files changed, 15 insertions(+), 123 deletions(-) diff --git a/pkg6repo/src/e2e_tests.rs b/pkg6repo/src/e2e_tests.rs index 89d81c6..b0270dd 100644 --- a/pkg6repo/src/e2e_tests.rs +++ b/pkg6repo/src/e2e_tests.rs @@ -389,124 +389,4 @@ mod e2e_tests { // Clean up cleanup_test_dir(&test_dir); } - - #[test] - fn test_e2e_import_pkg5_directory() { - // Get the path to the sample pkg5 repository - let sample_repo_path = PathBuf::from(env::current_dir().unwrap()) - .join("sample_data") - .join("sample-repo"); - - // Check if the sample repository exists - if !sample_repo_path.exists() { - println!( - "Sample pkg5 repository not found at {}, skipping test", - sample_repo_path.display() - ); - return; - } - - // Create a test directory - let test_dir = create_test_dir("e2e_import_pkg5_directory"); - let repo_path = test_dir.join("repo"); - - // Import the pkg5 repository using pkg6repo - let result = run_pkg6repo(&[ - "import-pkg5", - "--source", - sample_repo_path.to_str().unwrap(), - "--destination", - repo_path.to_str().unwrap(), - ]); - assert!( - result.is_ok(), - "Failed to import pkg5 repository: {:?}", - result.err() - ); - - // Check that the repository was created - assert!(repo_path.exists()); - assert!(repo_path.join("catalog").exists()); - assert!(repo_path.join("file").exists()); - assert!(repo_path.join("index").exists()); - assert!(repo_path.join("pkg").exists()); - assert!(repo_path.join("pkg6.repository").exists()); - - // Check that the publisher was imported - assert!(repo_path.join("pkg").join("openindiana.org").exists()); - - // List packages using pkg6repo - let result = run_pkg6repo(&["list", "-s", repo_path.to_str().unwrap()]); - assert!( - result.is_ok(), - "Failed to list packages: {:?}", - result.err() - ); - - let output = result.unwrap(); - assert!(!output.is_empty(), "No packages found in repository"); - - // Clean up - cleanup_test_dir(&test_dir); - } - - #[test] - fn test_e2e_import_pkg5_archive() { - // Get the path to the sample pkg5 p5p archive - let sample_p5p_path = PathBuf::from(env::current_dir().unwrap()) - .join("sample_data") - .join("sample-repo.p5p"); - - // Check if the sample p5p archive exists - if !sample_p5p_path.exists() { - println!( - "Sample pkg5 p5p archive not found at {}, skipping test", - sample_p5p_path.display() - ); - return; - } - - // Create a test directory - let test_dir = create_test_dir("e2e_import_pkg5_archive"); - let repo_path = test_dir.join("repo"); - - // Import the pkg5 p5p archive using pkg6repo - let result = run_pkg6repo(&[ - "import-pkg5", - "--source", - sample_p5p_path.to_str().unwrap(), - "--destination", - repo_path.to_str().unwrap(), - ]); - assert!( - result.is_ok(), - "Failed to import pkg5 p5p archive: {:?}", - result.err() - ); - - // Check that the repository was created - assert!(repo_path.exists()); - assert!(repo_path.join("catalog").exists()); - assert!(repo_path.join("file").exists()); - assert!(repo_path.join("index").exists()); - assert!(repo_path.join("pkg").exists()); - assert!(repo_path.join("pkg6.repository").exists()); - - // Check that the publisher was imported - assert!(repo_path.join("pkg").join("openindiana.org").exists()); - - // List packages using pkg6repo - let result = run_pkg6repo(&["list", "-s", repo_path.to_str().unwrap()]); - assert!( - result.is_ok(), - "Failed to list packages: {:?}", - result.err() - ); - - let output = result.unwrap(); - assert!(!output.is_empty(), "No packages found in repository"); - - // Clean up - cleanup_test_dir(&test_dir); - } -} +} \ No newline at end of file diff --git a/pkg6repo/src/pkg5_import.rs b/pkg6repo/src/pkg5_import.rs index 15f234d..09ca7a0 100644 --- a/pkg6repo/src/pkg5_import.rs +++ b/pkg6repo/src/pkg5_import.rs @@ -397,8 +397,20 @@ impl Pkg5Importer { let hash = payload.primary_identifier.hash.clone(); // Determine the file path in the source repository - let hash_prefix = &hash[0..2]; - let file_path = file_dir.join(hash_prefix).join(&hash); + // Try the new two-level hierarchy first (first two characters, then next two characters) + let first_two = &hash[0..2]; + let next_two = &hash[2..4]; + let file_path_new = file_dir.join(first_two).join(next_two).join(&hash); + + // Fall back to the old one-level hierarchy if the file doesn't exist in the new structure + let file_path_old = file_dir.join(first_two).join(&hash); + + // Use the path that exists + let file_path = if file_path_new.exists() { + file_path_new + } else { + file_path_old + }; if !file_path.exists() { warn!(