-
-
Notifications
You must be signed in to change notification settings - Fork 769
refactor(lock): simplify lockfile to always use array format #7093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -136,31 +136,20 @@ impl Lockfile { | |||||
| .try_into()?; | ||||||
|
|
||||||
| let mut lockfile = Lockfile::default(); | ||||||
| let mut has_single_version_format = false; | ||||||
|
|
||||||
| for (short, value) in tools { | ||||||
| let versions = match value { | ||||||
| toml::Value::Array(arr) => arr | ||||||
| .into_iter() | ||||||
| .map(LockfileTool::try_from) | ||||||
| .collect::<Result<Vec<_>>>()?, | ||||||
| _ => { | ||||||
| // Single-Version format detected - will be auto-migrated | ||||||
| has_single_version_format = true; | ||||||
| trace!("Auto-migrating single-version format for tool: {}", short); | ||||||
| vec![LockfileTool::try_from(value)?] | ||||||
| } | ||||||
| _ => bail!( | ||||||
| "invalid lockfile format for tool {short}: expected array ([[tools.{short}]])" | ||||||
| ), | ||||||
| }; | ||||||
| lockfile.tools.insert(short, versions); | ||||||
| } | ||||||
|
|
||||||
| if has_single_version_format { | ||||||
| debug!( | ||||||
| "Auto-migrated lockfile from single-version to multi-version format: {}", | ||||||
| path.display() | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| Ok(lockfile) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -559,24 +548,8 @@ impl From<ToolVersionList> for Vec<LockfileTool> { | |||||
| fn format(mut doc: DocumentMut) -> String { | ||||||
| if let Some(tools) = doc.get_mut("tools") { | ||||||
| for (_k, v) in tools.as_table_mut().unwrap().iter_mut() { | ||||||
| match v { | ||||||
| toml_edit::Item::ArrayOfTables(art) => { | ||||||
| for t in art.iter_mut() { | ||||||
| t.sort_values_by(|a, _, b, _| { | ||||||
| if a == "version" { | ||||||
| return std::cmp::Ordering::Less; | ||||||
| } | ||||||
| a.to_string().cmp(&b.to_string()) | ||||||
| }); | ||||||
| // Sort platforms section within each tool | ||||||
| if let Some(toml_edit::Item::Table(platforms_table)) = | ||||||
| t.get_mut("platforms") | ||||||
| { | ||||||
| platforms_table.sort_values(); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| toml_edit::Item::Table(t) => { | ||||||
| if let toml_edit::Item::ArrayOfTables(art) = v { | ||||||
| for t in art.iter_mut() { | ||||||
| t.sort_values_by(|a, _, b, _| { | ||||||
|
Comment on lines
+551
to
553
|
||||||
| if a == "version" { | ||||||
| return std::cmp::Ordering::Less; | ||||||
|
|
@@ -588,7 +561,6 @@ fn format(mut doc: DocumentMut) -> String { | |||||
| platforms_table.sort_values(); | ||||||
| } | ||||||
| } | ||||||
| _ => {} | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -602,10 +574,10 @@ mod tests { | |||||
| use std::collections::BTreeMap; | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_multi_version_format_migration() { | ||||||
| // Test that single-version format is read correctly and writes as multi-version | ||||||
| let single_version_toml = r#" | ||||||
| [tools.node] | ||||||
| fn test_array_format_required() { | ||||||
|
||||||
| fn test_array_format_required() { | |
| fn test_lockfile_parses_array_format() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Old-format lockfiles silently lose locked version data
The refactoring rejects old single-version lockfile format with a
bail!()error, but the callers ofLockfile::readcatch this error viahandle_missing_lockfileand silently return an empty lockfile. This means users with old-format lockfiles will have their locked versions silently discarded (with only a warning logged), and the lockfile will be overwritten with fresh version data. The intent to reject old format conflicts with the lenient error handling that treats parse failures the same as missing files.Additional Locations (1)
src/lockfile.rs#L413-L416