Skip to content
Snippets Groups Projects
Commit 0a2c98d9 authored by Simon Sapin's avatar Simon Sapin
Browse files

Import std modules

parent be651cc5
No related branches found
No related tags found
1 merge request!1Initial implementation
......@@ -2,4 +2,6 @@
use dialoguer::Confirm;
use indicatif::BinaryBytes;
use sha2::{Digest, Sha256};
use std::fs;
use std::io;
use std::io::Seek;
......@@ -5,3 +7,2 @@
use std::io::Seek;
use std::io::Write;
use std::path::PathBuf;
......@@ -7,4 +8,6 @@
use std::path::PathBuf;
use std::process;
use std::str;
use structopt::StructOpt;
#[derive(StructOpt)]
......@@ -39,7 +42,7 @@
"New dataset from directory {}",
style(self.directory.display()).bold()
);
if !std::fs::metadata(&self.directory)?.is_dir() {
if !fs::metadata(&self.directory)?.is_dir() {
Err("Not a directory")?
}
......@@ -50,10 +53,10 @@
.to_str()
.ok_or("Non-Unicode base name")?;
let today = time::OffsetDateTime::now_utc().date();
let hg_id_output = std::process::Command::new("hg")
let hg_id_output = process::Command::new("hg")
.arg("id")
.arg("--id")
.arg("-R")
.arg(&self.directory)
.output()?;
let id = if hg_id_output.status.success() {
......@@ -54,8 +57,8 @@
.arg("id")
.arg("--id")
.arg("-R")
.arg(&self.directory)
.output()?;
let id = if hg_id_output.status.success() {
format!("_{}", std::str::from_utf8(&hg_id_output.stdout)?.trim())
format!("_{}", str::from_utf8(&hg_id_output.stdout)?.trim())
} else {
......@@ -61,5 +64,5 @@
} else {
let hg_stderr = String::from_utf8_lossy(&hg_id_output.stderr);
let hg_stderr = str::from_utf8(&hg_id_output.stderr)?;
eprintln!("{}", style(hg_stderr.trim()).red());
println!("Not a Mercurial repository?");
format!("")
......@@ -118,7 +121,7 @@
impl Megafine {
fn new() -> Result<Self> {
let exe = std::fs::canonicalize(std::env::current_exe()?)?;
let exe = fs::canonicalize(std::env::current_exe()?)?;
// TODO: use a `try` block when available
// https://github.com/rust-lang/rust/issues/31436
......@@ -139,7 +142,7 @@
)
})?;
let tmp_dir = repo.join("tmp");
std::fs::create_dir_all(&tmp_dir)?;
fs::create_dir_all(&tmp_dir)?;
Ok(Self { tmp_dir })
}
......@@ -159,10 +162,10 @@
if !message.is_empty() {
eprintln!("{}", message)
}
std::process::exit(1)
process::exit(1)
}
}
}
struct Tee<A, B>(A, B);
......@@ -163,12 +166,12 @@
}
}
}
struct Tee<A, B>(A, B);
impl<A: Write, B: Write> Write for Tee<A, B> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
impl<A: io::Write, B: io::Write> io::Write for Tee<A, B> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)?;
self.1.write(buf)
}
......@@ -171,8 +174,8 @@
self.0.write(buf)?;
self.1.write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
fn flush(&mut self) -> io::Result<()> {
self.0.flush()?;
self.1.flush()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment