Skip to content

Commit d8e03d7

Browse files
authored
Merge pull request #311 from hydro-project/fix-310
handle read-only `Cargo.lock` files, fix #310
2 parents 8996340 + 52272f3 commit d8e03d7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/cargo.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ pub(crate) fn manifest_dir() -> Result<Directory> {
7373
pub(crate) fn build_dependencies(project: &mut Project) -> Result<()> {
7474
let workspace_cargo_lock = path!(project.workspace / "Cargo.lock");
7575
if workspace_cargo_lock.exists() {
76-
let _ = fs::copy(workspace_cargo_lock, path!(project.dir / "Cargo.lock"));
76+
let dest_lockfile = path!(project.dir / "Cargo.lock");
77+
let _ = fs::copy(workspace_cargo_lock, &dest_lockfile);
78+
79+
// Ensure the destination file is writable in case the source was read-only
80+
if let Ok(metadata) = fs::metadata(&dest_lockfile) {
81+
let mut permissions = metadata.permissions();
82+
if permissions.readonly() {
83+
permissions.set_readonly(false);
84+
let _ = fs::set_permissions(&dest_lockfile, permissions);
85+
}
86+
}
7787
} else {
7888
let _ = cargo(project).arg("generate-lockfile").status();
7989
}

0 commit comments

Comments
 (0)