mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Fix bug in helpers::create_if_not_exist
Returned `File` must be both readable and writable. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
09d210bf62
commit
d9fe7bfaf4
1 changed files with 7 additions and 2 deletions
|
@ -53,13 +53,18 @@ pub fn cargo_home() -> Result<&'static Path, io::Error> {
|
||||||
.map(ops::Deref::deref)
|
.map(ops::Deref::deref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returned file is readable and writable.
|
||||||
pub fn create_if_not_exist(path: impl AsRef<Path>) -> io::Result<fs::File> {
|
pub fn create_if_not_exist(path: impl AsRef<Path>) -> io::Result<fs::File> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
fs::File::options()
|
let mut options = fs::File::options();
|
||||||
|
options.read(true).write(true);
|
||||||
|
|
||||||
|
options
|
||||||
|
.clone()
|
||||||
.create_new(true)
|
.create_new(true)
|
||||||
.open(path)
|
.open(path)
|
||||||
.or_else(|_| fs::File::open(path))
|
.or_else(|_| options.open(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn await_task<T>(task: tokio::task::JoinHandle<miette::Result<T>>) -> miette::Result<T> {
|
pub async fn await_task<T>(task: tokio::task::JoinHandle<miette::Result<T>>) -> miette::Result<T> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue