lockfile: add pakku v0 compatibility and ProjectFile serde defaults
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I48a03feeb6bb2e640b41a85ba3e0e3296a6a6964
This commit is contained in:
parent
a642b976e9
commit
3faf4d3ca8
2 changed files with 13 additions and 20 deletions
|
|
@ -308,7 +308,7 @@ mod tests {
|
|||
}
|
||||
|
||||
let found = lockfile.get_project("test-id").unwrap();
|
||||
assert_eq!(found.redistributable, false);
|
||||
assert!(!found.redistributable);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -566,8 +566,7 @@ mod tests {
|
|||
|
||||
/// Current lockfile version - bump this when making breaking changes
|
||||
const LOCKFILE_VERSION: u32 = 2;
|
||||
/// Minimum supported lockfile version for migration
|
||||
const MIN_SUPPORTED_VERSION: u32 = 1;
|
||||
|
||||
const LOCKFILE_NAME: &str = "pakku-lock.json";
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
@ -577,6 +576,7 @@ pub struct LockFile {
|
|||
pub mc_versions: Vec<String>,
|
||||
pub loaders: HashMap<String, String>,
|
||||
pub projects: Vec<Project>,
|
||||
#[serde(default)]
|
||||
pub lockfile_version: u32,
|
||||
}
|
||||
|
||||
|
|
@ -642,7 +642,7 @@ impl LockFile {
|
|||
|
||||
// Check if migration is needed
|
||||
if lockfile.lockfile_version < LOCKFILE_VERSION {
|
||||
lockfile = lockfile.migrate()?;
|
||||
lockfile = lockfile.migrate();
|
||||
// Save migrated lockfile
|
||||
lockfile.save_without_validation(path_ref)?;
|
||||
log::info!(
|
||||
|
|
@ -661,12 +661,11 @@ impl LockFile {
|
|||
}
|
||||
|
||||
/// Migrate lockfile from older version to current version
|
||||
fn migrate(mut self) -> Result<Self> {
|
||||
if self.lockfile_version < MIN_SUPPORTED_VERSION {
|
||||
return Err(PakkerError::InvalidLockFile(format!(
|
||||
"Lockfile version {} is too old to migrate. Minimum supported: {}",
|
||||
self.lockfile_version, MIN_SUPPORTED_VERSION
|
||||
)));
|
||||
fn migrate(mut self) -> Self {
|
||||
// Migration from v0 (pakku format, no explicit version) to v1
|
||||
if self.lockfile_version == 0 {
|
||||
log::info!("Migrating lockfile from v0 (pakku format) to v1...");
|
||||
self.lockfile_version = 1;
|
||||
}
|
||||
|
||||
// Migration from v1 to v2
|
||||
|
|
@ -693,7 +692,7 @@ impl LockFile {
|
|||
// self.lockfile_version = 3;
|
||||
// }
|
||||
|
||||
Ok(self)
|
||||
self
|
||||
}
|
||||
|
||||
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||
|
|
@ -719,13 +718,6 @@ impl LockFile {
|
|||
self.lockfile_version, LOCKFILE_VERSION
|
||||
)));
|
||||
}
|
||||
if self.lockfile_version < MIN_SUPPORTED_VERSION {
|
||||
return Err(PakkerError::InvalidLockFile(format!(
|
||||
"Lockfile version {} is too old. Minimum supported: {}",
|
||||
self.lockfile_version, MIN_SUPPORTED_VERSION
|
||||
)));
|
||||
}
|
||||
|
||||
if self.mc_versions.is_empty() {
|
||||
return Err(PakkerError::InvalidLockFile(
|
||||
"At least one Minecraft version is required".to_string(),
|
||||
|
|
|
|||
|
|
@ -370,6 +370,7 @@ pub struct ProjectFile {
|
|||
#[serde(rename = "type")]
|
||||
pub file_type: String,
|
||||
pub file_name: String,
|
||||
#[serde(default)]
|
||||
pub mc_versions: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub loaders: Vec<String>,
|
||||
|
|
@ -378,6 +379,7 @@ pub struct ProjectFile {
|
|||
pub id: String,
|
||||
pub parent_id: String,
|
||||
pub hashes: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub required_dependencies: Vec<String>,
|
||||
pub size: u64,
|
||||
pub date_published: String,
|
||||
|
|
@ -551,8 +553,7 @@ mod tests {
|
|||
|
||||
assert!(
|
||||
file.is_compatible(&lockfile_mc, &lockfile_loaders),
|
||||
"Failed for valid loader: {}",
|
||||
loader
|
||||
"Failed for valid loader: {loader}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue