Skip to content
Snippets Groups Projects
Commit 7b6bd6f6 authored by Brian Lewis's avatar Brian Lewis
Browse files

Fix some dangling todos

parent d35923c8
No related branches found
Tags 0.5.0
2 merge requests!2Ingest different DRS formats,!1Ingest
Pipeline #16269 passed
......@@ -145,12 +145,18 @@ async fn ingest_structure(
};
if entry.path().is_file() {
// TODO: this conversion should probably take place within drs
let path = Utf8PathBuf::from_path_buf(entry.path().to_path_buf()).unwrap();
// TODO: this should too
if !structure.verify_path(&path) {
continue;
}
let path = match Utf8PathBuf::from_path_buf(entry.path().to_path_buf()) {
Ok(p) => p,
Err(e) => {
warn!(
"{} not a valid drs file, has non UTF8 characters in path:\n{:?}",
entry.path().display(),
e
);
skipped += 1;
continue;
}
};
let f = match structure.file_from_path(&path) {
Ok(f) => f,
......
......@@ -87,7 +87,7 @@ impl Structure {
/// This is not comprehensive in that there are still paths where this would return `true` but which are not valid
/// for this structure. For example, if a path has the same `root_dir` and the same _number_ of components in its
/// directory structure, it will pass this even if it doesn't have the right `filename` structure for this.
/// *TODO*: fix this if possible.
/// TODO: fix this if possible.
pub fn verify_path<P: AsRef<Path>>(&self, path: P) -> bool {
let path = path.as_ref();
......@@ -113,6 +113,13 @@ impl Structure {
/// Extracts [`Metadata`] for a file path of this structure
pub fn file_from_path(&self, path: &Utf8PathBuf) -> Result<Metadata, Error> {
if !self.verify_path(&path) {
return Err(Error::InvalidPath {
path: path.into(),
reason: "file path does not match expected structure".to_owned(),
});
}
let parts = path
.strip_prefix(self.root())
.unwrap() // this is already done with `structure_from_path` so should be safe
......@@ -268,8 +275,6 @@ impl TryFrom<&String> for Config {
/// Paths must be UTF-8.
#[derive(Debug, PartialEq)]
pub struct Metadata<'a> {
// File doesn't feel quite right as a name since it isn't an open file but more of a path?
// in original, this is the string key rather than the actual structure but I think this can work here
structure: &'a Structure,
/// map of { part name => value } e.g. "institute" => "cpc"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment