mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
Mark the unwrap and Sweep the unwrap a bit more.
This commit is contained in:
parent
8d5fd6f379
commit
1e8793135a
3 changed files with 27 additions and 17 deletions
|
@ -79,15 +79,19 @@ fn cp(
|
||||||
if entry.is_file() {
|
if entry.is_file() {
|
||||||
let strategy = |(source_file, _depth_level)| {
|
let strategy = |(source_file, _depth_level)| {
|
||||||
if destination.exists() {
|
if destination.exists() {
|
||||||
let mut new_dst = dunce::canonicalize(destination.clone()).unwrap();
|
let mut new_dst = dunce::canonicalize(destination.clone())?;
|
||||||
new_dst.push(entry.file_name().unwrap());
|
if let Some(name) = entry.file_name() {
|
||||||
(source_file, new_dst)
|
new_dst.push(name);
|
||||||
|
}
|
||||||
|
Ok((source_file, new_dst))
|
||||||
} else {
|
} else {
|
||||||
(source_file, destination.clone())
|
Ok((source_file, destination.clone()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ref src, ref dst) in sources.paths_applying_with(strategy) {
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_file() {
|
if src.is_file() {
|
||||||
match std::fs::copy(src, dst) {
|
match std::fs::copy(src, dst) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -118,7 +122,7 @@ fn cp(
|
||||||
|
|
||||||
let strategy = |(source_file, depth_level)| {
|
let strategy = |(source_file, depth_level)| {
|
||||||
let mut new_dst = destination.clone();
|
let mut new_dst = destination.clone();
|
||||||
let path = dunce::canonicalize(&source_file).unwrap();
|
let path = dunce::canonicalize(&source_file)?;
|
||||||
|
|
||||||
let mut comps: Vec<_> = path
|
let mut comps: Vec<_> = path
|
||||||
.components()
|
.components()
|
||||||
|
@ -133,10 +137,12 @@ fn cp(
|
||||||
new_dst.push(fragment);
|
new_dst.push(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
(PathBuf::from(&source_file), PathBuf::from(new_dst))
|
Ok((PathBuf::from(&source_file), PathBuf::from(new_dst)))
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ref src, ref dst) in sources.paths_applying_with(strategy) {
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_dir() {
|
if src.is_dir() {
|
||||||
if !dst.exists() {
|
if !dst.exists() {
|
||||||
match std::fs::create_dir_all(dst) {
|
match std::fs::create_dir_all(dst) {
|
||||||
|
@ -189,8 +195,8 @@ fn cp(
|
||||||
};
|
};
|
||||||
|
|
||||||
let strategy = |(source_file, depth_level)| {
|
let strategy = |(source_file, depth_level)| {
|
||||||
let mut new_dst = dunce::canonicalize(&destination).unwrap();
|
let mut new_dst = dunce::canonicalize(&destination)?;
|
||||||
let path = dunce::canonicalize(&source_file).unwrap();
|
let path = dunce::canonicalize(&source_file)?;
|
||||||
|
|
||||||
let mut comps: Vec<_> = path
|
let mut comps: Vec<_> = path
|
||||||
.components()
|
.components()
|
||||||
|
@ -205,10 +211,12 @@ fn cp(
|
||||||
new_dst.push(fragment);
|
new_dst.push(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
(PathBuf::from(&source_file), PathBuf::from(new_dst))
|
Ok((PathBuf::from(&source_file), PathBuf::from(new_dst)))
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ref src, ref dst) in sources.paths_applying_with(strategy) {
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_dir() {
|
if src.is_dir() {
|
||||||
if !dst.exists() {
|
if !dst.exists() {
|
||||||
match std::fs::create_dir_all(dst) {
|
match std::fs::create_dir_all(dst) {
|
||||||
|
|
|
@ -181,7 +181,7 @@ fn mv(
|
||||||
let strategy = |(source_file, depth_level)| {
|
let strategy = |(source_file, depth_level)| {
|
||||||
let mut new_dst = destination.clone();
|
let mut new_dst = destination.clone();
|
||||||
|
|
||||||
let path = dunce::canonicalize(&source_file).unwrap();
|
let path = dunce::canonicalize(&source_file)?;
|
||||||
|
|
||||||
let mut comps: Vec<_> = path
|
let mut comps: Vec<_> = path
|
||||||
.components()
|
.components()
|
||||||
|
@ -196,10 +196,12 @@ fn mv(
|
||||||
new_dst.push(fragment);
|
new_dst.push(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
(PathBuf::from(&source_file), PathBuf::from(new_dst))
|
Ok((PathBuf::from(&source_file), PathBuf::from(new_dst)))
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ref src, ref dst) in sources.paths_applying_with(strategy) {
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_dir() {
|
if src.is_dir() {
|
||||||
if !dst.exists() {
|
if !dst.exists() {
|
||||||
match std::fs::create_dir_all(dst) {
|
match std::fs::create_dir_all(dst) {
|
||||||
|
|
|
@ -105,9 +105,9 @@ impl FileStructure {
|
||||||
self.root = path.to_path_buf();
|
self.root = path.to_path_buf();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paths_applying_with<F>(&mut self, to: F) -> Vec<(PathBuf, PathBuf)>
|
pub fn paths_applying_with<F>(&mut self, to: F) -> Result<Vec<(PathBuf, PathBuf)>, Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
F: Fn((PathBuf, usize)) -> (PathBuf, PathBuf),
|
F: Fn((PathBuf, usize)) -> Result<(PathBuf, PathBuf), Box<dyn std::error::Error>>,
|
||||||
{
|
{
|
||||||
self.resources
|
self.resources
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in a new issue