Skip to content

Commit

Permalink
treefile: Return . instead of "" for parent directory
Browse files Browse the repository at this point in the history
This addresses the root cause of
coreos#4029

Basically we were calling `set_repos_dir("")` on the libdnf side
and it simply did not handle that, failing to open the directory.

(Though I'm not saying "Closes" since we should still fix the
 file monitoring stuff)

I don't yet know why this seemed to work in some cases but not
others though.
  • Loading branch information
cgwalters committed Jan 24, 2023
1 parent 3b5da6c commit 88f15b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ impl Treefile {
/// The main treefile creation entrypoint.
#[instrument]
fn new_boxed(filename: &Utf8Path, basearch: Option<&str>) -> Result<Box<Treefile>> {
let directory = filename
.parent()
let directory = utils::parent_dir_utf8(filename)
.ok_or_else(|| anyhow!("{} is not a file path", filename))
.map(|v| Some(v.to_owned()))?;
let parsed = treefile_parse_and_process(filename, basearch)?;
Expand Down
8 changes: 8 additions & 0 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use crate::cxxrsutil::*;
use crate::variant_utils;
use anyhow::{bail, Context, Result};
use camino::Utf8Path;
use glib::Variant;
use once_cell::sync::Lazy;
use ostree_ext::prelude::*;
Expand Down Expand Up @@ -147,6 +148,13 @@ pub fn parent_dir(filename: &Path) -> Option<&Path> {
.map(|p| if p.as_os_str() == "" { ".".as_ref() } else { p })
}

/// Like [`parent_dir`] above but for UTF-8 paths.
pub fn parent_dir_utf8(filename: &Utf8Path) -> Option<&Utf8Path> {
filename
.parent()
.map(|p| if p.as_os_str() == "" { ".".as_ref() } else { p })
}

/// Call a faillible future, while monitoring `cancellable` and return an error if cancelled.
pub(crate) async fn run_with_cancellable<F, R>(
f: F,
Expand Down

0 comments on commit 88f15b2

Please sign in to comment.