agent: Fix needless_borrow warnings

As we bumped the rust toolchain to 1.66.0, some new warnings have been
raised due to needless_borrow.

Let's fix them all here.

For more info about the warnings, please, take a look at:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2023-01-02 14:49:10 +01:00
parent 7bcdc9049a
commit f77220490e
7 changed files with 24 additions and 24 deletions

View File

@ -414,7 +414,7 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> {
// Scan scsi host passing in the channel, SCSI id and LUN.
// Channel is always 0 because we have only one SCSI controller.
let scan_data = format!("0 {} {}", tokens[0], tokens[1]);
let scan_data = &format!("0 {} {}", tokens[0], tokens[1]);
for entry in fs::read_dir(SYSFS_SCSI_HOST_PATH)? {
let host = entry?.file_name();
@ -428,7 +428,7 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> {
let scan_path = PathBuf::from(&format!("{}/{}/{}", SYSFS_SCSI_HOST_PATH, host_str, "scan"));
fs::write(scan_path, &scan_data)?;
fs::write(scan_path, scan_data)?;
}
Ok(())
@ -1531,7 +1531,7 @@ mod tests {
pci_driver_override(syspci, dev0, "drv_b").unwrap();
assert_eq!(fs::read_to_string(&dev0override).unwrap(), "drv_b");
assert_eq!(fs::read_to_string(&probepath).unwrap(), dev0.to_string());
assert_eq!(fs::read_to_string(&drvaunbind).unwrap(), dev0.to_string());
assert_eq!(fs::read_to_string(drvaunbind).unwrap(), dev0.to_string());
}
#[test]
@ -1543,7 +1543,7 @@ mod tests {
let dev0 = pci::Address::new(0, 0, pci::SlotFn::new(0, 0).unwrap());
let dev0path = syspci.join("devices").join(dev0.to_string());
fs::create_dir_all(&dev0path).unwrap();
fs::create_dir_all(dev0path).unwrap();
// Test dev0
assert!(pci_iommu_group(&syspci, dev0).unwrap().is_none());
@ -1554,7 +1554,7 @@ mod tests {
let dev1group = dev1path.join("iommu_group");
fs::create_dir_all(&dev1path).unwrap();
std::os::unix::fs::symlink("../../../kernel/iommu_groups/12", &dev1group).unwrap();
std::os::unix::fs::symlink("../../../kernel/iommu_groups/12", dev1group).unwrap();
// Test dev1
assert_eq!(
@ -1567,7 +1567,7 @@ mod tests {
let dev2path = syspci.join("devices").join(dev2.to_string());
let dev2group = dev2path.join("iommu_group");
fs::create_dir_all(&dev2group).unwrap();
fs::create_dir_all(dev2group).unwrap();
// Test dev2
assert!(pci_iommu_group(&syspci, dev2).is_err());

View File

@ -648,7 +648,7 @@ pub fn recursive_ownership_change(
) -> Result<()> {
let mut mask = if read_only { RO_MASK } else { RW_MASK };
if path.is_dir() {
for entry in fs::read_dir(&path)? {
for entry in fs::read_dir(path)? {
recursive_ownership_change(entry?.path().as_path(), uid, gid, read_only)?;
}
mask |= EXEC_MASK;
@ -894,7 +894,7 @@ pub fn get_cgroup_mounts(
}]);
}
let file = File::open(&cg_path)?;
let file = File::open(cg_path)?;
let reader = BufReader::new(file);
let mut has_device_cgroup = false;
@ -1777,7 +1777,7 @@ mod tests {
let tempdir = tempdir().unwrap();
let src = if d.mask_src {
tempdir.path().join(&d.src)
tempdir.path().join(d.src)
} else {
Path::new(d.src).to_path_buf()
};

View File

@ -88,7 +88,7 @@ impl Namespace {
}
let logger = self.logger.clone();
let new_ns_path = ns_path.join(&ns_type.get());
let new_ns_path = ns_path.join(ns_type.get());
File::create(new_ns_path.as_path())?;
@ -102,7 +102,7 @@ impl Namespace {
let source = Path::new(&origin_ns_path);
let destination = new_ns_path.as_path();
File::open(&source)?;
File::open(source)?;
// Create a new netns on the current thread.
let cf = ns_type.get_flags();

View File

@ -946,13 +946,13 @@ mod tests {
fn clean_env_for_test_add_one_arp_neighbor(dummy_name: &str, ip: &str) {
// ip link delete dummy
Command::new("ip")
.args(&["link", "delete", dummy_name])
.args(["link", "delete", dummy_name])
.output()
.expect("prepare: failed to delete dummy");
// ip neigh del dev dummy ip
Command::new("ip")
.args(&["neigh", "del", dummy_name, ip])
.args(["neigh", "del", dummy_name, ip])
.output()
.expect("prepare: failed to delete neigh");
}
@ -967,19 +967,19 @@ mod tests {
// ip link add dummy type dummy
Command::new("ip")
.args(&["link", "add", dummy_name, "type", "dummy"])
.args(["link", "add", dummy_name, "type", "dummy"])
.output()
.expect("failed to add dummy interface");
// ip addr add 192.168.0.2/16 dev dummy
Command::new("ip")
.args(&["addr", "add", "192.168.0.2/16", "dev", dummy_name])
.args(["addr", "add", "192.168.0.2/16", "dev", dummy_name])
.output()
.expect("failed to add ip for dummy");
// ip link set dummy up;
Command::new("ip")
.args(&["link", "set", dummy_name, "up"])
.args(["link", "set", dummy_name, "up"])
.output()
.expect("failed to up dummy");
}
@ -1011,7 +1011,7 @@ mod tests {
// ip neigh show dev dummy ip
let stdout = Command::new("ip")
.args(&["neigh", "show", "dev", dummy_name, to_ip])
.args(["neigh", "show", "dev", dummy_name, to_ip])
.output()
.expect("failed to show neigh")
.stdout;

View File

@ -64,7 +64,7 @@ fn do_setup_guest_dns(logger: Logger, dns_list: Vec<String>, src: &str, dst: &st
.map(|x| x.trim())
.collect::<Vec<&str>>()
.join("\n");
fs::write(src, &content)?;
fs::write(src, content)?;
// bind mount to /etc/resolv.conf
mount::mount(Some(src), dst, Some("bind"), MsFlags::MS_BIND, None::<&str>)

View File

@ -1072,7 +1072,7 @@ mod tests {
fs::create_dir(&subdir_path).unwrap();
for file in j.files {
let subfile_path = format!("{}/{}", subdir_path, file.name);
let mut subfile = File::create(&subfile_path).unwrap();
let mut subfile = File::create(subfile_path).unwrap();
subfile.write_all(file.content.as_bytes()).unwrap();
}
}

View File

@ -124,7 +124,7 @@ impl Storage {
// if we are creating a directory: just create it, nothing more to do
if metadata.file_type().is_dir() {
let dest_file_path = self.make_target_path(&source_file_path)?;
let dest_file_path = self.make_target_path(source_file_path)?;
fs::create_dir_all(&dest_file_path)
.await
@ -152,7 +152,7 @@ impl Storage {
// Assume target mount is a file path
self.target_mount_point.clone()
} else {
let dest_file_path = self.make_target_path(&source_file_path)?;
let dest_file_path = self.make_target_path(source_file_path)?;
if let Some(path) = dest_file_path.parent() {
debug!(logger, "Creating destination directory: {}", path.display());
@ -778,7 +778,7 @@ mod tests {
22
);
assert_eq!(
fs::read_to_string(&entries.0[0].target_mount_point.as_path().join("1.txt")).unwrap(),
fs::read_to_string(entries.0[0].target_mount_point.as_path().join("1.txt")).unwrap(),
"updated"
);
@ -823,7 +823,7 @@ mod tests {
2
);
assert_eq!(
fs::read_to_string(&entries.0[1].target_mount_point.as_path().join("foo.txt")).unwrap(),
fs::read_to_string(entries.0[1].target_mount_point.as_path().join("foo.txt")).unwrap(),
"updated"
);
@ -1000,7 +1000,7 @@ mod tests {
// create a path we'll remove later
fs::create_dir_all(source_dir.path().join("tmp")).unwrap();
fs::write(&source_dir.path().join("tmp/test-file"), "foo").unwrap();
fs::write(source_dir.path().join("tmp/test-file"), "foo").unwrap();
assert_eq!(entry.scan(&logger).await.unwrap(), 3); // root, ./tmp, test-file
// Verify expected directory, file: