mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
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:
parent
7bcdc9049a
commit
f77220490e
@ -414,7 +414,7 @@ fn scan_scsi_bus(scsi_addr: &str) -> Result<()> {
|
|||||||
|
|
||||||
// Scan scsi host passing in the channel, SCSI id and LUN.
|
// Scan scsi host passing in the channel, SCSI id and LUN.
|
||||||
// Channel is always 0 because we have only one SCSI controller.
|
// 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)? {
|
for entry in fs::read_dir(SYSFS_SCSI_HOST_PATH)? {
|
||||||
let host = entry?.file_name();
|
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"));
|
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(())
|
Ok(())
|
||||||
@ -1531,7 +1531,7 @@ mod tests {
|
|||||||
pci_driver_override(syspci, dev0, "drv_b").unwrap();
|
pci_driver_override(syspci, dev0, "drv_b").unwrap();
|
||||||
assert_eq!(fs::read_to_string(&dev0override).unwrap(), "drv_b");
|
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(&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]
|
#[test]
|
||||||
@ -1543,7 +1543,7 @@ mod tests {
|
|||||||
let dev0 = pci::Address::new(0, 0, pci::SlotFn::new(0, 0).unwrap());
|
let dev0 = pci::Address::new(0, 0, pci::SlotFn::new(0, 0).unwrap());
|
||||||
let dev0path = syspci.join("devices").join(dev0.to_string());
|
let dev0path = syspci.join("devices").join(dev0.to_string());
|
||||||
|
|
||||||
fs::create_dir_all(&dev0path).unwrap();
|
fs::create_dir_all(dev0path).unwrap();
|
||||||
|
|
||||||
// Test dev0
|
// Test dev0
|
||||||
assert!(pci_iommu_group(&syspci, dev0).unwrap().is_none());
|
assert!(pci_iommu_group(&syspci, dev0).unwrap().is_none());
|
||||||
@ -1554,7 +1554,7 @@ mod tests {
|
|||||||
let dev1group = dev1path.join("iommu_group");
|
let dev1group = dev1path.join("iommu_group");
|
||||||
|
|
||||||
fs::create_dir_all(&dev1path).unwrap();
|
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
|
// Test dev1
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1567,7 +1567,7 @@ mod tests {
|
|||||||
let dev2path = syspci.join("devices").join(dev2.to_string());
|
let dev2path = syspci.join("devices").join(dev2.to_string());
|
||||||
let dev2group = dev2path.join("iommu_group");
|
let dev2group = dev2path.join("iommu_group");
|
||||||
|
|
||||||
fs::create_dir_all(&dev2group).unwrap();
|
fs::create_dir_all(dev2group).unwrap();
|
||||||
|
|
||||||
// Test dev2
|
// Test dev2
|
||||||
assert!(pci_iommu_group(&syspci, dev2).is_err());
|
assert!(pci_iommu_group(&syspci, dev2).is_err());
|
||||||
|
@ -648,7 +648,7 @@ pub fn recursive_ownership_change(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut mask = if read_only { RO_MASK } else { RW_MASK };
|
let mut mask = if read_only { RO_MASK } else { RW_MASK };
|
||||||
if path.is_dir() {
|
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)?;
|
recursive_ownership_change(entry?.path().as_path(), uid, gid, read_only)?;
|
||||||
}
|
}
|
||||||
mask |= EXEC_MASK;
|
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 reader = BufReader::new(file);
|
||||||
|
|
||||||
let mut has_device_cgroup = false;
|
let mut has_device_cgroup = false;
|
||||||
@ -1777,7 +1777,7 @@ mod tests {
|
|||||||
let tempdir = tempdir().unwrap();
|
let tempdir = tempdir().unwrap();
|
||||||
|
|
||||||
let src = if d.mask_src {
|
let src = if d.mask_src {
|
||||||
tempdir.path().join(&d.src)
|
tempdir.path().join(d.src)
|
||||||
} else {
|
} else {
|
||||||
Path::new(d.src).to_path_buf()
|
Path::new(d.src).to_path_buf()
|
||||||
};
|
};
|
||||||
|
@ -88,7 +88,7 @@ impl Namespace {
|
|||||||
}
|
}
|
||||||
let logger = self.logger.clone();
|
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())?;
|
File::create(new_ns_path.as_path())?;
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ impl Namespace {
|
|||||||
let source = Path::new(&origin_ns_path);
|
let source = Path::new(&origin_ns_path);
|
||||||
let destination = new_ns_path.as_path();
|
let destination = new_ns_path.as_path();
|
||||||
|
|
||||||
File::open(&source)?;
|
File::open(source)?;
|
||||||
|
|
||||||
// Create a new netns on the current thread.
|
// Create a new netns on the current thread.
|
||||||
let cf = ns_type.get_flags();
|
let cf = ns_type.get_flags();
|
||||||
|
@ -946,13 +946,13 @@ mod tests {
|
|||||||
fn clean_env_for_test_add_one_arp_neighbor(dummy_name: &str, ip: &str) {
|
fn clean_env_for_test_add_one_arp_neighbor(dummy_name: &str, ip: &str) {
|
||||||
// ip link delete dummy
|
// ip link delete dummy
|
||||||
Command::new("ip")
|
Command::new("ip")
|
||||||
.args(&["link", "delete", dummy_name])
|
.args(["link", "delete", dummy_name])
|
||||||
.output()
|
.output()
|
||||||
.expect("prepare: failed to delete dummy");
|
.expect("prepare: failed to delete dummy");
|
||||||
|
|
||||||
// ip neigh del dev dummy ip
|
// ip neigh del dev dummy ip
|
||||||
Command::new("ip")
|
Command::new("ip")
|
||||||
.args(&["neigh", "del", dummy_name, ip])
|
.args(["neigh", "del", dummy_name, ip])
|
||||||
.output()
|
.output()
|
||||||
.expect("prepare: failed to delete neigh");
|
.expect("prepare: failed to delete neigh");
|
||||||
}
|
}
|
||||||
@ -967,19 +967,19 @@ mod tests {
|
|||||||
|
|
||||||
// ip link add dummy type dummy
|
// ip link add dummy type dummy
|
||||||
Command::new("ip")
|
Command::new("ip")
|
||||||
.args(&["link", "add", dummy_name, "type", "dummy"])
|
.args(["link", "add", dummy_name, "type", "dummy"])
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to add dummy interface");
|
.expect("failed to add dummy interface");
|
||||||
|
|
||||||
// ip addr add 192.168.0.2/16 dev dummy
|
// ip addr add 192.168.0.2/16 dev dummy
|
||||||
Command::new("ip")
|
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()
|
.output()
|
||||||
.expect("failed to add ip for dummy");
|
.expect("failed to add ip for dummy");
|
||||||
|
|
||||||
// ip link set dummy up;
|
// ip link set dummy up;
|
||||||
Command::new("ip")
|
Command::new("ip")
|
||||||
.args(&["link", "set", dummy_name, "up"])
|
.args(["link", "set", dummy_name, "up"])
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to up dummy");
|
.expect("failed to up dummy");
|
||||||
}
|
}
|
||||||
@ -1011,7 +1011,7 @@ mod tests {
|
|||||||
|
|
||||||
// ip neigh show dev dummy ip
|
// ip neigh show dev dummy ip
|
||||||
let stdout = Command::new("ip")
|
let stdout = Command::new("ip")
|
||||||
.args(&["neigh", "show", "dev", dummy_name, to_ip])
|
.args(["neigh", "show", "dev", dummy_name, to_ip])
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to show neigh")
|
.expect("failed to show neigh")
|
||||||
.stdout;
|
.stdout;
|
||||||
|
@ -64,7 +64,7 @@ fn do_setup_guest_dns(logger: Logger, dns_list: Vec<String>, src: &str, dst: &st
|
|||||||
.map(|x| x.trim())
|
.map(|x| x.trim())
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
fs::write(src, &content)?;
|
fs::write(src, content)?;
|
||||||
|
|
||||||
// bind mount to /etc/resolv.conf
|
// bind mount to /etc/resolv.conf
|
||||||
mount::mount(Some(src), dst, Some("bind"), MsFlags::MS_BIND, None::<&str>)
|
mount::mount(Some(src), dst, Some("bind"), MsFlags::MS_BIND, None::<&str>)
|
||||||
|
@ -1072,7 +1072,7 @@ mod tests {
|
|||||||
fs::create_dir(&subdir_path).unwrap();
|
fs::create_dir(&subdir_path).unwrap();
|
||||||
for file in j.files {
|
for file in j.files {
|
||||||
let subfile_path = format!("{}/{}", subdir_path, file.name);
|
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();
|
subfile.write_all(file.content.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ impl Storage {
|
|||||||
|
|
||||||
// if we are creating a directory: just create it, nothing more to do
|
// if we are creating a directory: just create it, nothing more to do
|
||||||
if metadata.file_type().is_dir() {
|
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)
|
fs::create_dir_all(&dest_file_path)
|
||||||
.await
|
.await
|
||||||
@ -152,7 +152,7 @@ impl Storage {
|
|||||||
// Assume target mount is a file path
|
// Assume target mount is a file path
|
||||||
self.target_mount_point.clone()
|
self.target_mount_point.clone()
|
||||||
} else {
|
} 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() {
|
if let Some(path) = dest_file_path.parent() {
|
||||||
debug!(logger, "Creating destination directory: {}", path.display());
|
debug!(logger, "Creating destination directory: {}", path.display());
|
||||||
@ -778,7 +778,7 @@ mod tests {
|
|||||||
22
|
22
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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"
|
"updated"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -823,7 +823,7 @@ mod tests {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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"
|
"updated"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1000,7 +1000,7 @@ mod tests {
|
|||||||
|
|
||||||
// create a path we'll remove later
|
// create a path we'll remove later
|
||||||
fs::create_dir_all(source_dir.path().join("tmp")).unwrap();
|
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
|
assert_eq!(entry.scan(&logger).await.unwrap(), 3); // root, ./tmp, test-file
|
||||||
|
|
||||||
// Verify expected directory, file:
|
// Verify expected directory, file:
|
||||||
|
Loading…
Reference in New Issue
Block a user