Skip to content

Commit

Permalink
Merge pull request #382 from jplatte/jplatte/fs-imports
Browse files Browse the repository at this point in the history
Stop importing fs_err's free functions into scope
  • Loading branch information
ikeycode authored Jan 3, 2025
2 parents d7a6108 + 5be8cb2 commit 00163ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions boulder/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
thread,
};

use fs_err::{self as fs, read_dir};
use fs_err as fs;
use nix::unistd::{linkat, LinkatFlags};
use url::Url;

Expand All @@ -32,7 +32,7 @@ pub fn recreate_dir(path: &Path) -> io::Result<()> {
pub fn copy_dir(source_dir: &Path, out_dir: &Path) -> io::Result<()> {
recreate_dir(out_dir)?;

let contents = read_dir(source_dir)?;
let contents = fs::read_dir(source_dir)?;

for entry in contents.flatten() {
let path = entry.path();
Expand All @@ -58,7 +58,7 @@ pub fn enumerate_files<'a>(
dir: &'a Path,
matcher: impl Fn(&Path) -> bool + Send + Copy + 'a,
) -> io::Result<Vec<PathBuf>> {
let read_dir = read_dir(dir)?;
let read_dir = fs::read_dir(dir)?;

let mut paths = vec![];

Expand All @@ -78,7 +78,7 @@ pub fn enumerate_files<'a>(
}

pub fn list_dirs(dir: &Path) -> io::Result<Vec<PathBuf>> {
let read_dir = read_dir(dir)?;
let read_dir = fs::read_dir(dir)?;

let mut paths = vec![];

Expand Down
8 changes: 4 additions & 4 deletions crates/container/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::process::Command;
use std::ptr::addr_of_mut;
use std::sync::atomic::{AtomicI32, Ordering};

use fs_err::{copy, create_dir_all, remove_dir, PathExt as _};
use fs_err::{self as fs, PathExt as _};
use nix::libc::SIGCHLD;
use nix::mount::{mount, umount2, MntFlags, MsFlags};
use nix::sched::{clone, CloneFlags};
Expand Down Expand Up @@ -287,14 +287,14 @@ fn pivot(root: &Path, binds: &[Bind]) -> Result<(), ContainerError> {
)?;

umount2(OLD_PATH, MntFlags::MNT_DETACH).map_err(ContainerError::UnmountOldRoot)?;
remove_dir(OLD_PATH)?;
fs::remove_dir(OLD_PATH)?;

Ok(())
}

fn setup_networking(root: &Path) -> Result<(), ContainerError> {
ensure_directory(root.join("etc"))?;
copy("/etc/resolv.conf", root.join("etc/resolv.conf"))?;
fs::copy("/etc/resolv.conf", root.join("etc/resolv.conf"))?;
Ok(())
}

Expand All @@ -307,7 +307,7 @@ fn setup_localhost() -> Result<(), ContainerError> {
fn ensure_directory(path: impl AsRef<Path>) -> Result<(), ContainerError> {
let path = path.as_ref();
if !path.exists() {
create_dir_all(path)?;
fs::create_dir_all(path)?;
}
Ok(())
}
Expand Down
19 changes: 9 additions & 10 deletions moss/src/cli/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// SPDX-License-Identifier: MPL-2.0

use std::{
fs,
io::{copy, Read, Seek, SeekFrom},
os::unix::fs::symlink,
path::PathBuf,
};

use clap::{arg, ArgMatches, Command};
use fs_err::{create_dir_all, hard_link, remove_dir_all, remove_file, File};
use fs_err::{self as fs, File};
use moss::package::{self, MissingMetaFieldError};
use stone::{payload::layout, read::PayloadKind};
use thiserror::{self, Error};
Expand All @@ -33,7 +32,7 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {
.collect::<Vec<_>>();

// Begin unpack
create_dir_all(".stoneStore")?;
fs::create_dir_all(".stoneStore")?;

let content_store = PathBuf::from(".stoneStore");

Expand All @@ -53,7 +52,7 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {

// Cleanup old extraction root
if extraction_root.exists() {
remove_dir_all(&extraction_root)?;
fs::remove_dir_all(&extraction_root)?;
}

if let Some(content) = content {
Expand Down Expand Up @@ -90,7 +89,7 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {
})
.collect::<Result<Vec<_>, Error>>()?;

remove_file(".stoneContent")?;
fs::remove_file(".stoneContent")?;
}

if let Some(layouts) = layouts {
Expand All @@ -103,25 +102,25 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {
// drop it into a valid dir
// TODO: Fix the permissions & mask
let directory_target = target_disk.parent().unwrap();
create_dir_all(directory_target)?;
fs::create_dir_all(directory_target)?;

// link from CA store
hard_link(store_path, target_disk)?;
fs::hard_link(store_path, target_disk)?;
}
layout::Entry::Symlink(source, target) => {
let target_disk = extraction_root.join("usr").join(target);
let directory_target = target_disk.parent().unwrap();

// ensure dumping ground exists
create_dir_all(directory_target)?;
fs::create_dir_all(directory_target)?;

// join the link path to the directory target for relative joinery
symlink(source, target_disk)?;
}
layout::Entry::Directory(target) => {
let target_disk = extraction_root.join("usr").join(target);
// TODO: Fix perms!
create_dir_all(target_disk)?;
fs::create_dir_all(target_disk)?;
}
_ => unreachable!(),
}
Expand All @@ -130,7 +129,7 @@ pub fn handle(args: &ArgMatches) -> Result<(), Error> {
}

// Clean up.
remove_dir_all(content_store)?;
fs::remove_dir_all(content_store)?;

Ok(())
}
Expand Down
15 changes: 8 additions & 7 deletions moss/src/client/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
sync::{Arc, Mutex},
};

use fs_err::tokio::{self as fs, File};
use futures_util::StreamExt;
use thiserror::Error;
use tokio::io::AsyncWriteExt;
Expand Down Expand Up @@ -63,6 +62,8 @@ pub async fn fetch(
installation: &Installation,
on_progress: impl Fn(Progress),
) -> Result<Download, Error> {
use fs_err::tokio::{self as fs, File};

let url = meta.uri.as_ref().ok_or(Error::MissingUri)?.parse::<Url>()?;
let hash = meta.hash.as_ref().ok_or(Error::MissingHash)?;

Expand Down Expand Up @@ -134,8 +135,8 @@ impl Download {
unpacking_in_progress: UnpackingInProgress,
on_progress: impl Fn(Progress) + Send + 'static,
) -> Result<UnpackedAsset, Error> {
use fs_err::{create_dir_all, remove_file, File, OpenOptions};
use std::io::{copy, Read, Seek, SeekFrom, Write};
use fs_err::{self as fs, File, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Write};

struct ProgressWriter<'a, W> {
writer: W,
Expand Down Expand Up @@ -178,7 +179,7 @@ impl Download {
let content_dir = self.installation.cache_path("content");
let content_path = content_dir.join(self.id);

create_dir_all(&content_dir)?;
fs::create_dir_all(&content_dir)?;

let mut reader = stone::read(File::open(&self.path)?)?;

Expand Down Expand Up @@ -231,7 +232,7 @@ impl Download {

// Create parent dir
if let Some(parent) = path.parent() {
create_dir_all(parent)?;
fs::create_dir_all(parent)?;
}

// Split file reader over index range
Expand All @@ -241,7 +242,7 @@ impl Download {

let mut output = File::create(&path)?;

copy(&mut split_file, &mut output)?;
io::copy(&mut split_file, &mut output)?;

// Remove file from in-progress
unpacking_in_progress.remove(&path);
Expand All @@ -250,7 +251,7 @@ impl Download {
})
.collect::<Result<Vec<_>, Error>>()?;

remove_file(&content_path)?;
fs::remove_file(&content_path)?;

Ok(UnpackedAsset { payloads })
}
Expand Down
10 changes: 5 additions & 5 deletions moss/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
time::Duration,
};

use fs_err::{self as fs, create_dir_all};
use fs_err as fs;
use futures_util::{stream, StreamExt, TryStreamExt};
use nix::{
errno::Errno,
Expand Down Expand Up @@ -368,7 +368,7 @@ impl Client {
create_root_links(&self.installation.isolation_dir())?;

let etc = blit_root.join("etc");
create_dir_all(etc)?;
fs::create_dir_all(etc)?;

// ephemeral tx triggers
Self::apply_triggers(TriggerScope::Transaction(&self.installation, &self.scope), &fstree)?;
Expand All @@ -395,7 +395,7 @@ impl Client {

// Create the target tree
if !usr_target.try_exists()? {
create_dir_all(&usr_target)?;
fs::create_dir_all(&usr_target)?;
}

// Now swap staging with live
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Client {
let usr_source = self.installation.staging_path("usr");
if let Some(parent) = usr_target.parent() {
if !parent.exists() {
create_dir_all(parent)?;
fs::create_dir_all(parent)?;
}
}
// hot swap the staging/usr into the root/$id/usr
Expand Down Expand Up @@ -786,7 +786,7 @@ fn create_root_links(root: &Path) -> io::Result<()> {

fn record_state_id(root: &Path, state: state::Id) -> Result<(), Error> {
let usr = root.join("usr");
create_dir_all(&usr)?;
fs::create_dir_all(&usr)?;
let state_path = usr.join(".stateID");
fs::write(state_path, state.to_string())?;
Ok(())
Expand Down

0 comments on commit 00163ab

Please sign in to comment.