mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
feat: lockfile path move create logic into write_pkg_lockfile
This commit is contained in:
parent
c1ace2ad81
commit
d1b1b65a54
@ -84,6 +84,10 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
|
||||
anyhow::bail!("lock file version `{current_version:?}` requires `-Znext-lockfile-bump`")
|
||||
}
|
||||
|
||||
if !lock_root.as_path_unlocked().exists() {
|
||||
lock_root.create_dir()?;
|
||||
}
|
||||
|
||||
// Ok, if that didn't work just write it out
|
||||
lock_root
|
||||
.open_rw_exclusive_create(LOCKFILE_NAME, ws.gctx(), "Cargo.lock file")
|
||||
|
@ -1015,7 +1015,7 @@ pub fn lockfile_path(
|
||||
let path = gctx.cwd().join(lockfile_path);
|
||||
|
||||
if !path.ends_with(LOCKFILE_NAME) {
|
||||
bail!("the lockfile-path must be a path to a {LOCKFILE_NAME} file")
|
||||
bail!("the lockfile-path must be a path to a {LOCKFILE_NAME} file (please rename your lock file to {LOCKFILE_NAME})")
|
||||
}
|
||||
if path.is_dir() {
|
||||
bail!(
|
||||
@ -1023,12 +1023,6 @@ pub fn lockfile_path(
|
||||
lockfile_path.display()
|
||||
)
|
||||
}
|
||||
if !path.exists() {
|
||||
// Root case should already be covered above
|
||||
let parent_path = lockfile_path.parent().expect("lockfile path can't be root");
|
||||
|
||||
paths::create_dir_all(parent_path)?;
|
||||
}
|
||||
|
||||
return Ok(Some(path));
|
||||
}
|
||||
|
@ -135,19 +135,25 @@ fn broken_symlink() {
|
||||
assert!(!p.root().join(src).is_dir());
|
||||
|
||||
let err_msg = if !cfg!(windows) {
|
||||
str![[r#"[ERROR] failed to create directory `somedir/link`
|
||||
str![[
|
||||
r#"[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
|
||||
[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||
|
||||
Caused by:
|
||||
File exists (os error 17)
|
||||
|
||||
"#]]
|
||||
"#
|
||||
]]
|
||||
} else {
|
||||
str![[r#"[ERROR] failed to create directory `somedir/link`
|
||||
str![[
|
||||
r#"[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
|
||||
[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||
|
||||
Caused by:
|
||||
Cannot create a file when that file already exists. (os error 183)
|
||||
|
||||
"#]]
|
||||
"#
|
||||
]]
|
||||
};
|
||||
|
||||
make_execs(&mut p.cargo("metadata"), lockfile_path_argument.to_string())
|
||||
@ -173,19 +179,25 @@ fn loop_symlink() {
|
||||
assert!(!p.root().join(src).is_dir());
|
||||
|
||||
let err_msg = if !cfg!(windows) {
|
||||
str![[r#"[ERROR] failed to create directory `somedir/link`
|
||||
str![[
|
||||
r#"[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
|
||||
[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||
|
||||
Caused by:
|
||||
File exists (os error 17)
|
||||
|
||||
"#]]
|
||||
"#
|
||||
]]
|
||||
} else {
|
||||
str![[r#"[ERROR] failed to create directory `somedir/link`
|
||||
str![[
|
||||
r#"[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
|
||||
[ERROR] failed to create directory `[ROOT]/foo/somedir/link`
|
||||
|
||||
Caused by:
|
||||
Cannot create a file when that file already exists. (os error 183)
|
||||
|
||||
"#]]
|
||||
"#
|
||||
]]
|
||||
};
|
||||
|
||||
make_execs(&mut p.cargo("metadata"), lockfile_path_argument.to_string())
|
||||
|
Loading…
x
Reference in New Issue
Block a user