Add and use the camino
library for UTF-8 paths
ostree hard requires UTF-8 paths (and really we should never have any non-UTF-8 paths in the OS in general). The camino library has types that are both `Path` and `&str` and has a convenient `try_into()` too to avoid us duplicating the error handling.
This commit is contained in:
parent
ba7a72995b
commit
7b57f2b9d0
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1394,6 +1394,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"c_utf8",
|
||||
"camino",
|
||||
"chrono",
|
||||
"clap",
|
||||
"curl",
|
||||
|
@ -27,6 +27,7 @@ rpm = "4"
|
||||
[dependencies]
|
||||
anyhow = "1.0.40"
|
||||
c_utf8 = "0.1.0"
|
||||
camino = "1.0.4"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
clap = "2.33.3"
|
||||
curl = "0.4.36"
|
||||
|
@ -10,12 +10,14 @@ use crate::cxxrsutil::{CxxResult, FFIGObjectWrapper};
|
||||
use crate::passwd::PasswdDB;
|
||||
use crate::treefile::Treefile;
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use camino::Utf8Path;
|
||||
use fn_error_context::context;
|
||||
use gio::CancellableExt;
|
||||
use nix::sys::stat::Mode;
|
||||
use openat_ext::OpenatDirExt;
|
||||
use rayon::prelude::*;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Seek, Write};
|
||||
@ -648,13 +650,8 @@ fn convert_path_to_tmpfiles_d_recurse(
|
||||
};
|
||||
|
||||
let subpath = subpath?;
|
||||
let full_path = {
|
||||
let fname = subpath.file_name();
|
||||
let path_name = fname
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("invalid non-UTF-8 path: {:?}", fname))?;
|
||||
format!("{}/{}", ¤t_prefix, &path_name)
|
||||
};
|
||||
let fname: &Utf8Path = Path::new(subpath.file_name()).try_into()?;
|
||||
let full_path = format!("{}/{}", ¤t_prefix, fname);
|
||||
let path_type = subpath.simple_type().unwrap_or(SimpleType::Other);
|
||||
|
||||
// Workaround for nfs-utils in RHEL7:
|
||||
|
@ -3,15 +3,18 @@
|
||||
|
||||
use crate::cxxrsutil::*;
|
||||
use anyhow::{Context, Result};
|
||||
use camino::Utf8Path;
|
||||
use gio::prelude::*;
|
||||
use openat::SimpleType;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::HashSet;
|
||||
use std::convert::TryInto;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
use std::rc;
|
||||
use subprocess::Exec;
|
||||
@ -33,11 +36,7 @@ fn list_files_recurse<P: glib::IsA<gio::Cancellable>>(
|
||||
SimpleType::Dir => {
|
||||
for e in d.list_dir(path).context("readdir")? {
|
||||
let e = e.context("readdir")?;
|
||||
let name = e.file_name();
|
||||
let name = match name.to_str() {
|
||||
Some(n) => n,
|
||||
None => anyhow::bail!("Invalid UTF-8 name {}", name.to_string_lossy()),
|
||||
};
|
||||
let name: &Utf8Path = Path::new(e.file_name()).try_into()?;
|
||||
let subpath = format!("{}/{}", path, name);
|
||||
list_files_recurse(&d, &subpath, filelist, cancellable)?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user