feat: Add a way to unset a file name in an object store path

pull/24376/head
Carol (Nichols || Goulding) 2021-02-04 10:46:17 -05:00
parent c722188c5a
commit a7cd8a2796
2 changed files with 17 additions and 0 deletions

View File

@ -92,6 +92,11 @@ impl FilePath {
pub fn parts_after_prefix(&self, prefix: &Self) -> Option<Vec<PathPart>> {
self.inner.parts_after_prefix(&prefix.inner)
}
/// Remove this path's file name, if there is one.
pub fn unset_file_name(&mut self) {
self.inner = mem::take(&mut self.inner).unset_file_name();
}
}
impl From<FilePath> for DirsAndFileName {
@ -192,6 +197,13 @@ impl FilePathRepresentation {
Self::Parsed(dirs_and_file_name)
}
fn unset_file_name(self) -> Self {
let mut dirs_and_file_name: DirsAndFileName = self.into();
dirs_and_file_name.unset_file_name();
Self::Parsed(dirs_and_file_name)
}
/// Add the parts of `path` to the end of this path. Notably does
/// *not* behave as `PathBuf::push` does: there is no way to replace the
/// root. If `self` has a file name, that will be removed, then the

View File

@ -122,6 +122,11 @@ impl DirsAndFileName {
pub(crate) fn push_part_as_dir(&mut self, part: &PathPart) {
self.directories.push(part.to_owned());
}
/// Remove the file name, if any.
pub(crate) fn unset_file_name(&mut self) {
self.file_name = None;
}
}
#[cfg(test)]