Fix compiler warnings (#1361)

* env::home_dir is deprecated, compiler suggests to use crate `dirs`
* add superficial comments to file util module
This commit is contained in:
hashmap 2018-08-16 02:11:05 +02:00 committed by Ignotus Peverell
parent 6775112f61
commit 779921f71a
5 changed files with 36 additions and 13 deletions

11
Cargo.lock generated
View file

@ -336,6 +336,15 @@ name = "difference"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dirs"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.3"
@ -561,6 +570,7 @@ dependencies = [
name = "grin_config"
version = "0.3.0"
dependencies = [
"dirs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"grin_p2p 0.3.0",
"grin_servers 0.3.0",
"grin_util 0.3.0",
@ -1980,6 +1990,7 @@ dependencies = [
"checksum cursive 0.8.2-alpha.0 (git+https://github.com/yeastplume/Cursive?tag=grin_integration_1)" = "<none>"
"checksum daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4093d27eb267d617f03c2ee25d4c3ca525b89a76154001954a11984508ffbde5"
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
"checksum dirs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f679c09c1cf5428702cc10f6846c56e4e23420d3a88bcc9335b17c630a7b710b"
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum encode_unicode 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c088ec0ed2282dcd054f2c124c0327f953563e6c75fdc6ff5141779596289830"

View file

@ -9,6 +9,7 @@ publish = false
serde = "1"
serde_derive = "1"
toml = "0.4"
dirs = "1"
grin_servers = { path = "../servers" }
grin_p2p = { path = "../p2p" }

View file

@ -14,6 +14,7 @@
//! Configuration file management
use dirs;
use std::env;
use std::fs::File;
use std::io::Read;
@ -74,7 +75,7 @@ impl GlobalConfig {
return Ok(());
}
// Then look in {user_home}/.grin
let config_path = env::home_dir();
let config_path = dirs::home_dir();
if let Some(mut p) = config_path {
p.push(GRIN_HOME);
p.push(CONFIG_FILE_NAME);
@ -167,7 +168,8 @@ impl GlobalConfig {
/// Enable mining
pub fn stratum_enabled(&mut self) -> bool {
return self.members
return self
.members
.as_mut()
.unwrap()
.mining_server

View file

@ -23,6 +23,7 @@
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate dirs;
extern crate toml;
extern crate grin_p2p as p2p;

View file

@ -16,16 +16,18 @@ use std::io;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
pub fn delete(path_buf: PathBuf) -> io::Result<()>{
/// Delete a directory or file
pub fn delete(path_buf: PathBuf) -> io::Result<()> {
if path_buf.is_dir() {
fs::remove_dir_all(path_buf)
} else if path_buf.is_file() {
fs::remove_file(path_buf)
} else {
Ok(())
}
}
Ok(())
}
}
/// Copy directory, create destination if needed
pub fn copy_dir_to(src: &Path, dst: &Path) -> io::Result<u64> {
let mut counter = 0u64;
if !dst.is_dir() {
@ -36,15 +38,19 @@ pub fn copy_dir_to(src: &Path, dst: &Path) -> io::Result<u64> {
let entry = entry_result?;
let file_type = entry.file_type()?;
let count = copy_to(&entry.path(), &file_type, &dst.join(entry.file_name()))?;
counter +=count;
counter += count;
}
Ok(counter)
}
/// List directory
pub fn list_files(path: String) -> Vec<String> {
let mut files_vec: Vec<String> = vec![];
for entry in WalkDir::new(Path::new(&path)).into_iter().filter_map(|e| e.ok()) {
match entry.file_name().to_str(){
let mut files_vec: Vec<String> = vec![];
for entry in WalkDir::new(Path::new(&path))
.into_iter()
.filter_map(|e| e.ok())
{
match entry.file_name().to_str() {
Some(path_str) => files_vec.push(path_str.to_string()),
None => println!("Could not read optional type"),
}
@ -54,11 +60,13 @@ pub fn list_files(path: String) -> Vec<String> {
fn copy_to(src: &Path, src_type: &fs::FileType, dst: &Path) -> io::Result<u64> {
if src_type.is_file() {
fs::copy(src,dst)
fs::copy(src, dst)
} else if src_type.is_dir() {
copy_dir_to(src, dst)
} else {
return Err(io::Error::new(io::ErrorKind::Other, format!("Could not copy: {}", src.display())))
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Could not copy: {}", src.display()),
));
}
}