Skip to content

Commit

Permalink
Fix some clippy lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Apr 7, 2023
1 parent 6a5c902 commit 3cd2885
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cap-net-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl TcpListenerExt for TcpListener {
}

fn accept_with(&self, blocking: Blocking) -> io::Result<(TcpStream, SocketAddr)> {
let (stream, addr) = rustix::net::acceptfrom_with(&self, socket_flags(blocking))?;
let (stream, addr) = rustix::net::acceptfrom_with(self, socket_flags(blocking))?;
set_socket_flags(&stream, blocking)?;

// We know have a TCP socket, so we know we'll get an IP address.
Expand Down
2 changes: 1 addition & 1 deletion cap-primitives/src/fs/manually/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ pub(crate) fn stat(start: &fs::File, path: &Path, follow: FollowSymlinks) -> io:

// If the path ended in `.` or `..`, we already have it open, so just do
// `.metadata()` on it.
Metadata::from_file(&*ctx.base)
Metadata::from_file(&ctx.base)
}

/// Test whether the given options imply that we should treat an open file as
Expand Down
2 changes: 1 addition & 1 deletion cap-primitives/src/fs/via_parent/create_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn create_dir(start: &fs::File, path: &Path, options: &DirOptions) ->
// slashes.
let path = strip_dir_suffix(path);

let (dir, basename) = open_parent(start, &*path)?;
let (dir, basename) = open_parent(start, &path)?;

create_dir_unchecked(&dir, basename.as_ref(), options)
}
4 changes: 2 additions & 2 deletions cap-primitives/src/fs/via_parent/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub(crate) fn rename(
let old_path = strip_dir_suffix(old_path);
let new_path = strip_dir_suffix(new_path);

let (old_dir, old_basename) = open_parent(old_start, &*old_path)?;
let (new_dir, new_basename) = open_parent(new_start, &*new_path)?;
let (old_dir, old_basename) = open_parent(old_start, &old_path)?;
let (new_dir, new_basename) = open_parent(new_start, &new_path)?;

// On Unix, re-append a slash if needed.
#[cfg(unix)]
Expand Down
2 changes: 1 addition & 1 deletion cap-primitives/src/rustix/fs/dir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn open_ambient_dir_impl(
#[cfg(target_os = "wasi")]
options.directory(true);

options.open(&path)
options.open(path)
}

/// Use `O_PATH` on platforms which have it, or none otherwise.
Expand Down
2 changes: 1 addition & 1 deletion cap-primitives/src/rustix/fs/times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ pub(crate) fn set_times_follow_unchecked(
last_access: to_timespec(atime)?,
last_modification: to_timespec(mtime)?,
};
Ok(utimensat(&start, path, &times, AtFlags::empty())?)
Ok(utimensat(start, path, &times, AtFlags::empty())?)
}
2 changes: 1 addition & 1 deletion cap-primitives/src/rustix/linux/fs/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn set_permissions_through_proc_self_fd(

let dirfd = proc_self_fd()?;
let mode = Mode::from_bits(perm.mode() as RawMode).ok_or_else(errors::invalid_flags)?;
Ok(chmodat(&dirfd, DecInt::from_fd(&opath), mode)?)
Ok(chmodat(dirfd, DecInt::from_fd(&opath), mode)?)
}

pub(crate) fn set_times_through_proc_self_fd(
Expand Down
6 changes: 3 additions & 3 deletions cap-tempfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ impl TempDir {
pub fn new_in(dir: &Dir) -> io::Result<Self> {
for _ in 0..Self::num_iterations() {
let name = &Self::new_name();
match dir.create_dir(&name) {
match dir.create_dir(name) {
Ok(()) => {
let dir = match dir.open_dir(&name) {
let dir = match dir.open_dir(name) {
Ok(dir) => dir,
Err(e) => {
dir.remove_dir(name).ok();
Expand Down Expand Up @@ -203,7 +203,7 @@ where
Err(e) => return Err(e),
}
}
return Err(std::io::Error::new(err, "too many temporary files exist"));
Err(std::io::Error::new(err, "too many temporary files exist"))
}

#[test]
Expand Down
11 changes: 4 additions & 7 deletions cap-tempfile/src/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl<'d> Debug for TempFile<'d> {

#[cfg(any(target_os = "android", target_os = "linux"))]
fn new_tempfile_linux(d: &Dir, anonymous: bool) -> io::Result<Option<File>> {
use cap_std::io_lifetimes::OwnedFd;
use rustix::fs::{Mode, OFlags};
// openat's API uses WRONLY. There may be use cases for reading too, so let's
// support it.
Expand All @@ -74,15 +73,13 @@ fn new_tempfile_linux(d: &Dir, anonymous: bool) -> io::Result<Option<File>> {
let mode = Mode::from_raw_mode(0o666);
// Happy path - Linux with O_TMPFILE
match rustix::fs::openat(d, ".", oflags, mode) {
Ok(r) => return Ok(Some(File::from(OwnedFd::from(r)))),
Ok(r) => Ok(Some(File::from(r))),
// See <https://github.com/Stebalien/tempfile/blob/1a40687e06eb656044e3d2dffa1379f04b3ef3fd/src/file/imp/unix.rs#L81>
// TODO: With newer Rust versions, this could be simplied to only write `Err` once.
Err(rustix::io::Errno::OPNOTSUPP)
| Err(rustix::io::Errno::ISDIR)
| Err(rustix::io::Errno::NOENT) => Ok(None),
Err(e) => {
return Err(e.into());
}
Err(e) => Err(e.into()),
}
}

Expand All @@ -92,10 +89,10 @@ fn generate_name_in(subdir: &Dir, f: &File) -> io::Result<String> {
use rustix::fd::AsFd;
use rustix::fs::AtFlags;
let procself_fd = rustix::io::proc_self_fd()?;
let fdnum = rustix::path::DecInt::from_fd(&f.as_fd());
let fdnum = rustix::path::DecInt::from_fd(f.as_fd());
let fdnum = fdnum.as_c_str();
super::retry_with_name_ignoring(io::ErrorKind::AlreadyExists, |name| {
rustix::fs::linkat(&procself_fd, fdnum, subdir, name, AtFlags::SYMLINK_FOLLOW)
rustix::fs::linkat(procself_fd, fdnum, subdir, name, AtFlags::SYMLINK_FOLLOW)
.map_err(Into::into)
})
.map(|(_, name)| name)
Expand Down

0 comments on commit 3cd2885

Please sign in to comment.