Skip to content

Commit 78b422a

Browse files
cp: fix test failures
1 parent bdb5b26 commit 78b422a

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/uu/cp/src/cp.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub enum CpError {
5252
IoErr(#[from] io::Error),
5353

5454
/// Wrapper for io::Error with path context
55-
#[error("Reading from input {1} gave error")]
55+
#[error("{1}: {0}")]
5656
IoErrContext(io::Error, String),
5757

5858
/// General copy error
@@ -69,7 +69,7 @@ pub enum CpError {
6969
WalkDirErr(#[from] walkdir::Error),
7070

7171
/// Simple std::path::StripPrefixError wrapper
72-
#[error("{0}")]
72+
#[error(transparent)]
7373
StripPrefixError(#[from] StripPrefixError),
7474

7575
/// Result of a skipped file
@@ -1789,19 +1789,19 @@ fn symlink_file(
17891789
) -> CopyResult<()> {
17901790
#[cfg(not(windows))]
17911791
{
1792-
std::os::unix::fs::symlink(source, dest).map_err(|_| CpError::Error(format!(
1792+
std::os::unix::fs::symlink(source, dest).map_err(|e| CpError::IoErrContext(e, format!(
17931793
"cannot create symlink {} to {}",
17941794
get_filename(dest).unwrap_or("invalid file name").quote(),
17951795
get_filename(source).unwrap_or("invalid file name").quote()
17961796
)))?;
17971797
}
17981798
#[cfg(windows)]
17991799
{
1800-
std::os::windows::fs::symlink_file(source, dest).context(format!(
1800+
std::os::windows::fs::symlink_file(source, dest).map_err(|e| CpError::IoErrContext(e, format!(
18011801
"cannot create symlink {} to {}",
18021802
get_filename(dest).unwrap_or("invalid file name").quote(),
18031803
get_filename(source).unwrap_or("invalid file name").quote()
1804-
))?;
1804+
)))?;
18051805
}
18061806
if let Ok(file_info) = FileInformation::from_path(dest, false) {
18071807
symlinked_files.insert(file_info);
@@ -1976,7 +1976,7 @@ fn delete_dest_if_needed_and_allowed(
19761976
&FileInformation::from_path(
19771977
source,
19781978
options.dereference(source_in_command_line)
1979-
).map_err(|_| CpError::Error(format!("cannot stat {}", source.quote())))?
1979+
).map_err(|e| CpError::IoErrContext(e, format!("cannot stat {}", source.quote())))?
19801980
)
19811981
}
19821982
}
@@ -2117,7 +2117,7 @@ fn handle_copy_mode(
21172117
} else {
21182118
fs::hard_link(source, dest)
21192119
}
2120-
.map_err(|_| CpError::Error(format!(
2120+
.map_err(|e| CpError::IoErrContext(e, format!(
21212121
"cannot create hard link {} to {}",
21222122
get_filename(dest).unwrap_or("invalid file name").quote(),
21232123
get_filename(source).unwrap_or("invalid file name").quote()
@@ -2397,7 +2397,7 @@ fn copy_file(
23972397
// in the destination tree.
23982398
if let Some(new_source) = copied_files.get(
23992399
&FileInformation::from_path(source, options.dereference(source_in_command_line))
2400-
.map_err(|_| CpError::Error(format!("cannot stat {}", source.quote())))?,
2400+
.map_err(|e| CpError::IoErrContext(e, format!("cannot stat {}", source.quote())))?,
24012401
) {
24022402
fs::hard_link(new_source, dest)?;
24032403

src/uu/cp/src/platform/macos.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::path::Path;
1212
use uucore::buf_copy;
1313
use uucore::mode::get_umask;
1414

15-
use crate::{CopyDebug, CopyResult, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
15+
use crate::{CopyDebug, CopyResult, CpError, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
1616

1717
/// Copies `source` to `dest` using copy-on-write if possible.
1818
///
@@ -103,14 +103,14 @@ pub(crate) fn copy_on_write(
103103

104104
let context = buf_copy::copy_stream(&mut src_file, &mut dst_file)
105105
.map_err(|_| std::io::Error::from(std::io::ErrorKind::Other))
106-
.context(context)?;
106+
.map_err(|e| CpError::IoErrContext(e, context.to_owned())?;
107107

108108
if source_is_fifo {
109109
dst_file.set_permissions(src_file.metadata()?.permissions())?;
110110
}
111111
context
112112
} else {
113-
fs::copy(source, dest).context(context)?
113+
fs::copy(source, dest).map_err(|e| CpError::IoErrContext(e, context.to_owned())?;
114114
}
115115
}
116116
};

src/uu/cp/src/platform/other.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::fs;
77
use std::path::Path;
88

9-
use crate::{CopyDebug, CopyResult, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
9+
use crate::{CopyDebug, CopyResult, CpError, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
1010

1111
/// Copies `source` to `dest` for systems without copy-on-write
1212
pub(crate) fn copy_on_write(
@@ -29,7 +29,7 @@ pub(crate) fn copy_on_write(
2929
reflink: OffloadReflinkDebug::Unsupported,
3030
sparse_detection: SparseDebug::Unsupported,
3131
};
32-
fs::copy(source, dest).context(context)?;
32+
fs::copy(source, dest).map_err(|e| CpError::IoErrContext(e, context.to_owned())?;
3333

3434
Ok(copy_debug)
3535
}

src/uu/cp/src/platform/other_unix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::Path;
1010
use uucore::buf_copy;
1111
use uucore::mode::get_umask;
1212

13-
use crate::{CopyDebug, CopyResult, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
13+
use crate::{CopyDebug, CopyResult, CpError, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
1414

1515
/// Copies `source` to `dest` for systems without copy-on-write
1616
pub(crate) fn copy_on_write(
@@ -47,15 +47,15 @@ pub(crate) fn copy_on_write(
4747

4848
buf_copy::copy_stream(&mut src_file, &mut dst_file)
4949
.map_err(|_| std::io::Error::from(std::io::ErrorKind::Other))
50-
.context(context)?;
50+
.map_err(|e| CpError::IoErrContext(e, context.to_owned())?;
5151

5252
if source_is_fifo {
5353
dst_file.set_permissions(src_file.metadata()?.permissions())?;
5454
}
5555
return Ok(copy_debug);
5656
}
5757

58-
fs::copy(source, dest).context(context)?;
58+
fs::copy(source, dest).map_err(|e| CpError::IoErrContext(e, context.to_owned())?;
5959

6060
Ok(copy_debug)
6161
}

0 commit comments

Comments
 (0)