Skip to content

Commit

Permalink
Stable rust patch
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Oct 9, 2023
1 parent c8f9171 commit ca425ac
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ authors = ["Alex Saveau <[email protected]>"]
edition = "2021"
repository = "https://github.com/SUPERCILEX/fuc"
license = "Apache-2.0"
rust-version = "1.70"

[package]
name = "lint"
Expand Down
2 changes: 2 additions & 0 deletions cpz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ repository.workspace = true
keywords = ["tools", "files", "cp"]
categories = ["command-line-utilities", "development-tools", "filesystem"]
license.workspace = true
rust-version.workspace = true

[dependencies]
clap = { version = "4.4.6", features = ["derive", "wrap_help"] }
error-stack = "0.4.1"
fuc_engine = { version = "1", path = "../fuc_engine" }
once_cell = "1.18.0"
thiserror = "1.0.49"

[dev-dependencies]
Expand Down
11 changes: 5 additions & 6 deletions cpz/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#![feature(lazy_cell)]
#![feature(let_chains)]

use std::{
cell::LazyCell,
fs,
mem::swap,
path::{PathBuf, MAIN_SEPARATOR, MAIN_SEPARATOR_STR},
Expand All @@ -11,6 +7,7 @@ use std::{
use clap::{ArgAction, Parser, ValueHint};
use error_stack::Report;
use fuc_engine::{CopyOp, Error};
use once_cell::sync::Lazy as LazyCell;

/// A zippy alternative to `cp`, a tool to copy files and directories
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -142,8 +139,10 @@ fn copy(
let to = {
let is_into_directory = *is_into_directory;
let mut to = to;
if is_into_directory && let Some(name) = from.file_name() {
to.push(name);
if is_into_directory {
if let Some(name) = from.file_name() {
to.push(name);
}
}
to
};
Expand Down
2 changes: 2 additions & 0 deletions fuc_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ repository.workspace = true
keywords = ["tools", "files"]
categories = ["filesystem"]
license.workspace = true
rust-version.workspace = true

[dependencies]
crossbeam-channel = "0.5.8"
once_cell = "1.18.0"
thiserror = "1.0.49"
typed-builder = "0.16.2"

Expand Down
3 changes: 0 additions & 3 deletions fuc_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(lazy_cell)]
#![feature(lazy_cell_consume)]
#![feature(c_str_literals)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::used_underscore_binding)]
#![allow(clippy::needless_pass_by_value)]
Expand Down
15 changes: 9 additions & 6 deletions fuc_engine/src/ops/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn schedule_copies<
mod compat {
use std::{
borrow::Cow,
cell::{Cell, LazyCell},
cell::Cell,
ffi::{CStr, CString},
fs::File,
io,
Expand All @@ -150,6 +150,7 @@ mod compat {
};

use crossbeam_channel::{Receiver, Sender};
use once_cell::sync::Lazy as LazyCell;
use rustix::{
fs::{
copy_file_range, mkdirat, openat, readlinkat, statx, symlinkat, AtFlags, FileType,
Expand All @@ -167,6 +168,8 @@ mod compat {
Error,
};

const EMPTY: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") };

struct Impl<LF: FnOnce() -> (Sender<TreeNode>, JoinHandle<Result<(), Error>>)> {
#[allow(clippy::type_complexity)]
scheduling: LazyCell<(Sender<TreeNode>, JoinHandle<Result<(), Error>>), LF>,
Expand Down Expand Up @@ -199,7 +202,7 @@ mod compat {
fn finish(self) -> Result<(), Error> {
let Self { scheduling } = self;

if let Ok((tasks, thread)) = LazyCell::into_inner(scheduling) {
if let Ok((tasks, thread)) = LazyCell::into_value(scheduling) {
drop(tasks);
thread.join().map_err(|_| Error::Join)??;
}
Expand Down Expand Up @@ -288,8 +291,8 @@ mod compat {
continue;
}
{
let name = file.file_name();
if name == c"." || name == c".." {
let name = file.file_name().to_bytes();
if name == b"." || name == b".." {
continue;
}
}
Expand Down Expand Up @@ -333,7 +336,7 @@ mod compat {
to_path: &CString,
) -> Result<(), Error> {
let from_mode = {
let from_metadata = statx(from_dir, c"", AtFlags::EMPTY_PATH, StatxFlags::MODE)
let from_metadata = statx(from_dir, EMPTY, AtFlags::EMPTY_PATH, StatxFlags::MODE)
.map_io_err(|| format!("Failed to stat directory: {from_path:?}"))?;
Mode::from_raw_mode(from_metadata.stx_mode.into())
};
Expand Down Expand Up @@ -497,7 +500,7 @@ mod compat {
Ok(if let Some(ino) = root_to_inode {
ino
} else {
let to_metadata = statx(to_dir, c"", AtFlags::EMPTY_PATH, StatxFlags::INO)
let to_metadata = statx(to_dir, EMPTY, AtFlags::EMPTY_PATH, StatxFlags::INO)
.map_io_err(|| format!("Failed to stat directory: {to:?}"))?;
to_metadata.stx_ino
})
Expand Down
11 changes: 6 additions & 5 deletions fuc_engine/src/ops/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ fn schedule_deletions<'a, I: Into<Cow<'a, Path>>, F: IntoIterator<Item = I>>(
#[cfg(target_os = "linux")]
mod compat {
use std::{
borrow::Cow, cell::LazyCell, ffi::CString, mem::MaybeUninit, num::NonZeroUsize, path::Path,
sync::Arc, thread, thread::JoinHandle,
borrow::Cow, ffi::CString, mem::MaybeUninit, num::NonZeroUsize, path::Path, sync::Arc,
thread, thread::JoinHandle,
};

use crossbeam_channel::{Receiver, Sender};
use once_cell::sync::Lazy as LazyCell;
use rustix::{
fs::{openat, unlinkat, AtFlags, FileType, Mode, OFlags, RawDir, CWD},
thread::{unshare, UnshareFlags},
Expand Down Expand Up @@ -138,7 +139,7 @@ mod compat {
fn finish(self) -> Result<(), Error> {
let Self { scheduling } = self;

if let Ok((tasks, thread)) = LazyCell::into_inner(scheduling) {
if let Ok((tasks, thread)) = LazyCell::into_value(scheduling) {
drop(tasks);
thread.join().map_err(|_| Error::Join)??;
}
Expand Down Expand Up @@ -214,8 +215,8 @@ mod compat {
while let Some(file) = raw_dir.next() {
let file = file.map_io_err(|| format!("Failed to read directory: {:?}", node.path))?;
{
let name = file.file_name();
if name == c"." || name == c".." {
let name = file.file_name().to_bytes();
if name == b"." || name == b".." {
continue;
}
}
Expand Down
1 change: 1 addition & 0 deletions rmz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository.workspace = true
keywords = ["tools", "files", "rm"]
categories = ["command-line-utilities", "development-tools", "filesystem"]
license.workspace = true
rust-version.workspace = true

[dependencies]
clap = { version = "4.4.6", features = ["derive", "wrap_help"] }
Expand Down

0 comments on commit ca425ac

Please sign in to comment.