Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency upgrades and other maintenance #412

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 248 additions & 302 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ diesel = { version = "2.2.1", features = [
"returning_clauses_for_sqlite_3_35",
] }
diesel_migrations = "2.2.0"
dirs = "5.0.1"
dirs = "6.0.0"
elf = "0.7.4"
indicatif = "0.17.8"
itertools = "0.13.0"
fs-err = { version = "3.0.0", features = ["tokio"] }
itertools = "0.14.0"
fs-err = { version = "3.1.0", features = ["tokio"] }
futures-util = "0.3.31"
glob = "0.3.1"
hex = "0.4.3"
indextree = "4.6.1"
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
log = "0.4.22"
nom = "7.1.3"
nix = { version = "0.27.1", features = [
nix = { version = "0.29.0", features = [
"user",
"fs",
"sched",
Expand All @@ -51,7 +51,7 @@ nix = { version = "0.27.1", features = [
"signal",
"term",
] }
petgraph = "0.6.5"
petgraph = "0.7.1"
rayon = "1.10.0"
regex = "1.10.5"
reqwest = { version = "0.12.5", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/build/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Installed {
let target = dest_dir.join(name);

// Attempt hard link
let link_result = linkat(None, path, None, &target, LinkatFlags::NoSymlinkFollow);
let link_result = linkat(None, path, None, &target, LinkatFlags::AT_SYMLINK_NOFOLLOW);

// Copy instead
if link_result.is_err() {
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/package/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn emit_package(paths: &Paths, package: &Package<'_>) -> Result<(), Error> {
if !files.is_empty() {
// Temp file for building content payload
let temp_content_path = format!("/tmp/{}.tmp", &filename);
let mut temp_content = fs::OpenOptions::new()
let mut temp_content = File::options()
.read(true)
.append(true)
.create(true)
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn list_dirs(dir: &Path) -> io::Result<Vec<PathBuf>> {

pub fn hardlink_or_copy(from: &Path, to: &Path) -> io::Result<()> {
// Attempt hard link
let link_result = linkat(None, from, None, to, LinkatFlags::NoSymlinkFollow);
let link_result = linkat(None, from, None, to, LinkatFlags::AT_SYMLINK_NOFOLLOW);

// Copy instead
if link_result.is_err() {
Expand Down
51 changes: 23 additions & 28 deletions crates/container/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Container {
let rootless = !Uid::effective().is_root();

// Pipe to synchronize parent & child
let sync = pipe()?;
let (sync_r, sync_w) = pipe()?;

let mut flags =
CloneFlags::CLONE_NEWNS | CloneFlags::CLONE_NEWPID | CloneFlags::CLONE_NEWIPC | CloneFlags::CLONE_NEWUTS;
Expand All @@ -123,43 +123,38 @@ impl Container {
flags |= CloneFlags::CLONE_NEWNET;
}

let pid = unsafe {
clone(
Box::new(|| match enter(&self, sync, &mut f) {
Ok(_) => 0,
// Write error back to parent process
Err(error) => {
let error = format_error(error);
let mut pos = 0;
let sync_raw = (sync_r.as_raw_fd(), sync_w.as_raw_fd());
let clone_cb = Box::new(|| match enter(&self, sync_raw, &mut f) {
Ok(_) => 0,
// Write error back to parent process
Err(error) => {
let error = format_error(error);
let mut pos = 0;

while pos < error.len() {
let Ok(len) = write(sync.1, &error.as_bytes()[pos..]) else {
break;
};
while pos < error.len() {
let Ok(len) = write(&sync_w, &error.as_bytes()[pos..]) else {
break;
};

pos += len;
}
pos += len;
}

let _ = close(sync.1);
_ = close(sync_w.as_raw_fd());

1
}
}),
&mut *addr_of_mut!(STACK),
flags,
Some(SIGCHLD),
)?
};
1
}
});
let pid = unsafe { clone(clone_cb, &mut *addr_of_mut!(STACK), flags, Some(SIGCHLD))? };

// Update uid / gid map to map current user to root in container
if rootless {
idmap(pid)?;
}

// Allow child to continue
write(sync.1, &[Message::Continue as u8])?;
write(&sync_w, &[Message::Continue as u8])?;
// Write no longer needed
close(sync.1)?;
drop(sync_w);

if self.ignore_host_sigint {
ignore_sigint()?;
Expand All @@ -178,7 +173,7 @@ impl Container {
let mut buffer = [0u8; 1024];

loop {
let len = read(sync.0, &mut buffer)?;
let len = read(sync_r.as_raw_fd(), &mut buffer)?;

if len == 0 {
break;
Expand Down Expand Up @@ -382,7 +377,7 @@ pub fn set_term_fg(pgid: Pid) -> Result<(), nix::Error> {
)?
};
// Set term fg to pid
let res = tcsetpgrp(io::stdin().as_raw_fd(), pgid);
let res = tcsetpgrp(io::stdin(), pgid);
// Set up old handler
unsafe { sigaction(Signal::SIGTTOU, &prev_handler)? };

Expand Down
2 changes: 1 addition & 1 deletion moss/src/cli/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {
}

if let Some(content) = content {
let content_file = fs::OpenOptions::new()
let content_file = File::options()
.read(true)
.write(true)
.create(true)
Expand Down
4 changes: 2 additions & 2 deletions moss/src/client/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Download {
unpacking_in_progress: UnpackingInProgress,
on_progress: impl Fn(Progress) + Send + 'static,
) -> Result<UnpackedAsset, Error> {
use fs_err::{self as fs, File, OpenOptions};
use fs_err::{self as fs, File};
use std::io::{self, Read, Seek, SeekFrom, Write};

struct ProgressWriter<'a, W> {
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Download {
.find_map(PayloadKind::content)
.ok_or(Error::MissingContent)?;

let content_file = OpenOptions::new()
let content_file = File::options()
.read(true)
.write(true)
.create(true)
Expand Down
8 changes: 4 additions & 4 deletions moss/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ impl Client {
self.blit_element_item(parent, cache, name, item, stats)?;

// open the new dir
let newdir = fcntl::openat(parent, name, OFlag::O_RDONLY | OFlag::O_DIRECTORY, Mode::empty())?;
let newdir = fcntl::openat(Some(parent), name, OFlag::O_RDONLY | OFlag::O_DIRECTORY, Mode::empty())?;
for child in children.into_iter() {
self.blit_element(newdir, cache, child, progress, stats)?;
}
Expand Down Expand Up @@ -736,7 +736,7 @@ impl Client {
// https://github.com/serpent-os/tools/issues/372
0x99aa_06d3_0147_98d8_6001_c324_468d_497f => {
let fd = fcntl::openat(
parent,
Some(parent),
subpath,
OFlag::O_CREAT | OFlag::O_WRONLY | OFlag::O_TRUNC,
Mode::from_bits_truncate(item.layout.mode),
Expand All @@ -750,7 +750,7 @@ impl Client {
fp.to_str().unwrap(),
Some(parent),
subpath,
nix::unistd::LinkatFlags::NoSymlinkFollow,
nix::unistd::LinkatFlags::AT_SYMLINK_NOFOLLOW,
)?;

// Fix permissions
Expand All @@ -770,7 +770,7 @@ impl Client {
stats.num_symlinks += 1;
}
layout::Entry::Directory(_) => {
mkdirat(parent, subpath, Mode::from_bits_truncate(item.layout.mode))?;
mkdirat(Some(parent), subpath, Mode::from_bits_truncate(item.layout.mode))?;
stats.num_dirs += 1;
}

Expand Down
34 changes: 14 additions & 20 deletions moss/src/installation/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
//
// SPDX-License-Identifier: MPL-2.0

use std::{
fmt,
io::{self},
os::fd::AsRawFd,
path::PathBuf,
sync::Arc,
};

use fs_err::{self as fs, File};
use nix::fcntl::{flock, FlockArg};
use std::{fmt, io, path::PathBuf, sync::Arc};

use fs_err::File;
use nix::fcntl::{Flock, FlockArg};
use thiserror::Error;

/// An acquired file lock guaranteeing exclusive access
Expand All @@ -21,7 +15,7 @@ use thiserror::Error;
/// of this ref counted lock are dropped.
#[derive(Debug, Clone)]
#[allow(unused)]
pub struct Lock(Arc<File>);
pub struct Lock(Arc<Flock<std::fs::File>>);

/// Acquires a file lock at the provided path. If the file is currently
/// locked, `block_msg` will be displayed and the function will block
Expand All @@ -31,22 +25,22 @@ pub struct Lock(Arc<File>);
pub fn acquire(path: impl Into<PathBuf>, block_msg: impl fmt::Display) -> Result<Lock, Error> {
let path = path.into();

let file = fs::OpenOptions::new()
let (file, _) = File::options()
.create(true)
.write(true)
.truncate(false)
.open(path)?;
.open(path)?
.into_parts();

match flock(file.as_raw_fd(), FlockArg::LockExclusiveNonblock) {
Ok(_) => {}
Err(nix::errno::Errno::EWOULDBLOCK) => {
let flock = Flock::lock(file, FlockArg::LockExclusiveNonblock).or_else(|(file, e)| match e {
nix::errno::Errno::EWOULDBLOCK => {
println!("{block_msg}");
flock(file.as_raw_fd(), FlockArg::LockExclusive)?;
Flock::lock(file, FlockArg::LockExclusive).map_err(|(_, e)| e)
}
Err(e) => Err(e)?,
}
_ => Err(e),
})?;

Ok(Lock(Arc::new(file)))
Ok(Lock(Arc::new(flock)))
}

#[derive(Debug, Error)]
Expand Down
12 changes: 7 additions & 5 deletions moss/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ pub fn ignore(signals: impl IntoIterator<Item = Signal>) -> Result<Guard, Error>
Ok(Guard(
signals
.into_iter()
.map(|signal| unsafe {
let action = sigaction(
signal,
&SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty()),
)
.map(|signal| {
let action = unsafe {
sigaction(
signal,
&SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty()),
)
}
.map_err(Error::Ignore)?;

Ok(PrevHandler { signal, action })
Expand Down
Loading