diff --git a/src/model/lockfile.rs b/src/model/lockfile.rs index dc10595..1e56ab1 100644 --- a/src/model/lockfile.rs +++ b/src/model/lockfile.rs @@ -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, pub loaders: HashMap, pub projects: Vec, + #[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 { - 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>(&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(), diff --git a/src/model/project.rs b/src/model/project.rs index a9c7469..4ff7504 100644 --- a/src/model/project.rs +++ b/src/model/project.rs @@ -370,6 +370,7 @@ pub struct ProjectFile { #[serde(rename = "type")] pub file_type: String, pub file_name: String, + #[serde(default)] pub mc_versions: Vec, #[serde(default)] pub loaders: Vec, @@ -378,6 +379,7 @@ pub struct ProjectFile { pub id: String, pub parent_id: String, pub hashes: HashMap, + #[serde(default)] pub required_dependencies: Vec, 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}" ); } }