Skip to content

Commit ec59f0d

Browse files
vikram-kangotracakebaker
authored andcommitted
cp: fix fmt error
1 parent 3ca30c3 commit ec59f0d

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

src/uu/cp/src/copydir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use uucore::uio_error;
2626
use walkdir::{DirEntry, WalkDir};
2727

2828
use crate::{
29-
aligned_ancestors, context_for, copy_attributes, copy_file, copy_link, CopyResult, CpError, Options
29+
CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes, copy_file,
30+
copy_link,
3031
};
3132

3233
/// Ensure a Windows path starts with a `\\?`.

src/uu/cp/src/cp.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use std::collections::{HashMap, HashSet};
99
use std::ffi::OsString;
1010
use std::fmt::Display;
1111
use std::fs::{self, Metadata, OpenOptions, Permissions};
12-
use std::{fmt, io};
1312
#[cfg(unix)]
1413
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
1514
use std::path::{Path, PathBuf, StripPrefixError};
15+
use std::{fmt, io};
1616
#[cfg(all(unix, not(target_os = "android")))]
1717
use uucore::fsxattr::copy_xattrs;
1818

@@ -1679,7 +1679,8 @@ pub(crate) fn copy_attributes(
16791679
attributes: &Attributes,
16801680
) -> CopyResult<()> {
16811681
let context = &*format!("{} -> {}", source.quote(), dest.quote());
1682-
let source_metadata = fs::symlink_metadata(source).map_err(|e| CpError::IoErrContext(e, context.to_owned()))?;
1682+
let source_metadata =
1683+
fs::symlink_metadata(source).map_err(|e| CpError::IoErrContext(e, context.to_owned()))?;
16831684

16841685
// Ownership must be changed first to avoid interfering with mode change.
16851686
#[cfg(unix)]
@@ -1694,7 +1695,9 @@ pub(crate) fn copy_attributes(
16941695
// gnu compatibility: cp doesn't report an error if it fails to set the ownership.
16951696
let _ = wrap_chown(
16961697
dest,
1697-
&dest.symlink_metadata().map_err(|e| CpError::IoErrContext(e, context.to_owned()))?,
1698+
&dest
1699+
.symlink_metadata()
1700+
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?,
16981701
Some(dest_uid),
16991702
Some(dest_gid),
17001703
false,
@@ -1713,7 +1716,8 @@ pub(crate) fn copy_attributes(
17131716
// do nothing, since every symbolic link has the same
17141717
// permissions.
17151718
if !dest.is_symlink() {
1716-
fs::set_permissions(dest, source_metadata.permissions()).map_err(|e| CpError::IoErrContext(e, context.to_owned()))?;
1719+
fs::set_permissions(dest, source_metadata.permissions())
1720+
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?;
17171721
// FIXME: Implement this for windows as well
17181722
#[cfg(feature = "feat_acl")]
17191723
exacl::getfacl(source, None)
@@ -1789,19 +1793,29 @@ fn symlink_file(
17891793
) -> CopyResult<()> {
17901794
#[cfg(not(windows))]
17911795
{
1792-
std::os::unix::fs::symlink(source, dest).map_err(|e| CpError::IoErrContext(e, format!(
1793-
"cannot create symlink {} to {}",
1794-
get_filename(dest).unwrap_or("invalid file name").quote(),
1795-
get_filename(source).unwrap_or("invalid file name").quote()
1796-
)))?;
1796+
std::os::unix::fs::symlink(source, dest).map_err(|e| {
1797+
CpError::IoErrContext(
1798+
e,
1799+
format!(
1800+
"cannot create symlink {} to {}",
1801+
get_filename(dest).unwrap_or("invalid file name").quote(),
1802+
get_filename(source).unwrap_or("invalid file name").quote()
1803+
),
1804+
)
1805+
})?;
17971806
}
17981807
#[cfg(windows)]
17991808
{
1800-
std::os::windows::fs::symlink_file(source, dest).map_err(|e| CpError::IoErrContext(e, format!(
1801-
"cannot create symlink {} to {}",
1802-
get_filename(dest).unwrap_or("invalid file name").quote(),
1803-
get_filename(source).unwrap_or("invalid file name").quote()
1804-
)))?;
1809+
std::os::windows::fs::symlink_file(source, dest).map_err(|e| {
1810+
CpError::IoErrContext(
1811+
e,
1812+
format!(
1813+
"cannot create symlink {} to {}",
1814+
get_filename(dest).unwrap_or("invalid file name").quote(),
1815+
get_filename(source).unwrap_or("invalid file name").quote()
1816+
),
1817+
)
1818+
})?;
18051819
}
18061820
if let Ok(file_info) = FileInformation::from_path(dest, false) {
18071821
symlinked_files.insert(file_info);
@@ -2117,11 +2131,16 @@ fn handle_copy_mode(
21172131
} else {
21182132
fs::hard_link(source, dest)
21192133
}
2120-
.map_err(|e| CpError::IoErrContext(e, format!(
2121-
"cannot create hard link {} to {}",
2122-
get_filename(dest).unwrap_or("invalid file name").quote(),
2123-
get_filename(source).unwrap_or("invalid file name").quote()
2124-
)))?;
2134+
.map_err(|e| {
2135+
CpError::IoErrContext(
2136+
e,
2137+
format!(
2138+
"cannot create hard link {} to {}",
2139+
get_filename(dest).unwrap_or("invalid file name").quote(),
2140+
get_filename(source).unwrap_or("invalid file name").quote()
2141+
),
2142+
)
2143+
})?;
21252144
}
21262145
CopyMode::Copy => {
21272146
copy_helper(
@@ -2166,7 +2185,10 @@ fn handle_copy_mode(
21662185
return Ok(PerformedAction::Skipped);
21672186
}
21682187
UpdateMode::NoneFail => {
2169-
return Err(CpError::Error(format!("not replacing '{}'", dest.display())));
2188+
return Err(CpError::Error(format!(
2189+
"not replacing '{}'",
2190+
dest.display()
2191+
)));
21702192
}
21712193
UpdateMode::IfOlder => {
21722194
let dest_metadata = fs::symlink_metadata(dest)?;
@@ -2238,7 +2260,10 @@ fn calculate_dest_permissions(
22382260
context: &str,
22392261
) -> CopyResult<Permissions> {
22402262
if dest.exists() {
2241-
Ok(dest.symlink_metadata().map_err(|e| CpError::IoErrContext(e, context.to_owned()))?.permissions())
2263+
Ok(dest
2264+
.symlink_metadata()
2265+
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?
2266+
.permissions())
22422267
} else {
22432268
#[cfg(unix)]
22442269
{

src/uu/cp/src/platform/linux.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use uucore::buf_copy;
1616

1717
use uucore::mode::get_umask;
1818

19-
use crate::{CopyDebug, CopyResult, CpError, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
19+
use crate::{
20+
CopyDebug, CopyResult, CpError, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode,
21+
};
2022

2123
/// The fallback behavior for [`clone`] on failed system call.
2224
#[derive(Clone, Copy)]

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

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

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

1719
/// Copies `source` to `dest` using copy-on-write if possible.
1820
///
@@ -110,7 +112,8 @@ pub(crate) fn copy_on_write(
110112
}
111113
context
112114
} else {
113-
fs::copy(source, dest).map_err(|e| CpError::IoErrContext(e, context.to_owned()))?
115+
fs::copy(source, dest)
116+
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?
114117
}
115118
}
116119
};

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

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

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

1113
/// Copies `source` to `dest` for systems without copy-on-write
1214
pub(crate) fn copy_on_write(

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

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

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

1517
/// Copies `source` to `dest` for systems without copy-on-write
1618
pub(crate) fn copy_on_write(

0 commit comments

Comments
 (0)