diff --git a/pkg6repo/README.md b/pkg6repo/README.md index bc1decb..aaccb0c 100644 --- a/pkg6repo/README.md +++ b/pkg6repo/README.md @@ -158,6 +158,47 @@ pkg6repo refresh -s /path/to/repository --no-catalog pkg6repo refresh -s /path/to/repository --no-index ``` +### Import pkg5 Repository + +Import a pkg5 repository (directory-based or p5p archive) into a pkg6 repository: + +```bash +pkg6repo import-pkg5 --source /path/to/pkg5/repository --destination /path/to/pkg6/repository +``` + +You can specify a specific publisher to import: + +```bash +pkg6repo import-pkg5 --source /path/to/pkg5/repository --destination /path/to/pkg6/repository --publisher example.com +``` + +#### Importing from a Directory-Based Repository + +To import from a directory-based pkg5 repository: + +```bash +pkg6repo import-pkg5 --source /path/to/pkg5/repository/directory --destination /path/to/pkg6/repository +``` + +The source directory should contain the pkg5 repository structure with a `publisher` directory and a `pkg5.repository` file. + +#### Importing from a p5p Archive + +To import from a p5p archive: + +```bash +pkg6repo import-pkg5 --source /path/to/repository.p5p --destination /path/to/pkg6/repository +``` + +The p5p archive should be a valid pkg5 repository archive with the standard pkg5 repository structure. + +#### Notes + +- If the destination repository doesn't exist, it will be created automatically. +- If no publisher is specified, the first publisher found in the source repository will be used. +- The import process extracts files from the source repository, decompresses them if necessary, and adds them to the destination repository. +- After importing, the catalog and search index are automatically rebuilt. + ## License This project is licensed under the same license as the original IPS implementation. \ No newline at end of file diff --git a/pkg6repo/src/e2e_tests.rs b/pkg6repo/src/e2e_tests.rs index 035917d..b500dcc 100644 --- a/pkg6repo/src/e2e_tests.rs +++ b/pkg6repo/src/e2e_tests.rs @@ -372,4 +372,120 @@ 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); + } }