Add support for importing pkg5 repositories (directory and p5p format) into pkg6, update README with usage examples, and enhance e2e tests for validation.

This commit is contained in:
Till Wegmueller 2025-07-26 23:14:34 +02:00
parent c3ff6ac28e
commit ce535c830d
No known key found for this signature in database
2 changed files with 157 additions and 0 deletions

View file

@ -158,6 +158,47 @@ pkg6repo refresh -s /path/to/repository --no-catalog
pkg6repo refresh -s /path/to/repository --no-index 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 ## License
This project is licensed under the same license as the original IPS implementation. This project is licensed under the same license as the original IPS implementation.

View file

@ -372,4 +372,120 @@ mod e2e_tests {
// Clean up // Clean up
cleanup_test_dir(&test_dir); 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);
}
} }