-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:5ad45dc3
- Loading branch information
Showing
7 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::core::lockfile::Lockfile; | ||
use crate::core::Workspace; | ||
use anyhow::{Context, Result}; | ||
use fs4::FileExt; | ||
use std::fs::{File, OpenOptions}; | ||
use std::io::{Read, Write}; | ||
|
||
#[tracing::instrument(skip_all, level = "debug")] | ||
pub fn read_lockfile(ws: &Workspace<'_>) -> Result<Lockfile> { | ||
let mut file = OpenOptions::new() | ||
.read(true) | ||
.write(true) | ||
.create(true) | ||
.open(ws.lockfile_path()) | ||
.context("failed to open lockfile")?; | ||
|
||
file.lock_shared() | ||
.context("failed to acquire shared lockfile access")?; | ||
|
||
let mut content = String::new(); | ||
file.read_to_string(&mut content)?; | ||
|
||
content.try_into() | ||
} | ||
|
||
#[tracing::instrument(skip_all, level = "debug")] | ||
pub fn write_lockfile(lockfile: Lockfile, ws: &Workspace<'_>) -> Result<()> { | ||
let mut file = File::create(ws.lockfile_path()).context("failed to create lockfile")?; | ||
|
||
file.lock_exclusive() | ||
.context("failed to acquire exclusive lockfile access")?; | ||
|
||
file.write_all(lockfile.render()?.as_bytes()) | ||
.context("failed to write lockfile content")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ mod cache; | |
mod clean; | ||
mod compile; | ||
mod fmt; | ||
mod lockfile; | ||
mod manifest; | ||
mod metadata; | ||
mod new; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use assert_fs::fixture::ChildPath; | ||
use assert_fs::prelude::*; | ||
use indoc::indoc; | ||
use snapbox::cmd::Command; | ||
|
||
use scarb_test_support::cargo::cargo_bin; | ||
use test_for_each_example::test_for_each_example; | ||
|
||
#[test_for_each_example] | ||
fn create_lockfile_simple(example: &Path) { | ||
let lockfile = ChildPath::new(example.join("Scarb.lock")); | ||
if lockfile.exists() { | ||
fs::remove_file(&lockfile) | ||
.unwrap_or_else(|_| panic!("failed to remove {}", lockfile.to_str().unwrap())); | ||
} | ||
|
||
lockfile.assert(predicates::path::missing()); | ||
|
||
Command::new(cargo_bin("scarb")) | ||
.arg("fetch") | ||
.current_dir(example) | ||
.assert() | ||
.success(); | ||
|
||
lockfile.assert(predicates::path::exists()); | ||
lockfile.assert(predicates::str::starts_with(indoc! {r#" | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
[[package]] | ||
"#})); | ||
} |