Skip to content

Commit

Permalink
Remove tag namespace depth
Browse files Browse the repository at this point in the history
This was deemed unnecessary for disambiguation purposes and would only be
useful for supporting nesting namespaces, which we do not expect to support
at this time.

Signed-off-by: J Robert Ray <jrray@jrray.org>
  • Loading branch information
jrray committed May 25, 2023
1 parent 22f16d6 commit d870a5f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 41 deletions.
12 changes: 3 additions & 9 deletions crates/spfs/src/proto/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,8 @@ impl From<&storage::EntryType> for super::ls_tags_response::Entry {
storage::EntryType::Folder(e) => {
super::ls_tags_response::entry::Kind::Folder(e.to_owned())
}
storage::EntryType::Namespace { name, depth } => {
super::ls_tags_response::entry::Kind::Namespace(super::TagNamespace {
name: name.to_owned(),
depth: *depth,
})
storage::EntryType::Namespace(e) => {
super::ls_tags_response::entry::Kind::Namespace(e.to_owned())
}
storage::EntryType::Tag(e) => {
super::ls_tags_response::entry::Kind::Tag(e.to_owned())
Expand All @@ -353,10 +350,7 @@ impl TryFrom<super::ls_tags_response::Entry> for storage::EntryType {
Ok(storage::EntryType::Folder(e))
}
super::ls_tags_response::entry::Kind::Namespace(e) => {
Ok(storage::EntryType::Namespace {
name: e.name,
depth: e.depth,
})
Ok(storage::EntryType::Namespace(e))
}
super::ls_tags_response::entry::Kind::Tag(e) => Ok(storage::EntryType::Tag(e)),
},
Expand Down
7 changes: 1 addition & 6 deletions crates/spfs/src/proto/defs/tag.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ message Tag {
DateTime time = 6;
}

message TagNamespace {
string name = 1;
uint64 depth = 2;
}

message LsTagsRequest { string path = 1; }
message LsTagsResponse {
message Entry {
oneof kind {
string folder = 1;
string tag = 2;
TagNamespace namespace = 3;
string namespace = 3;
}
}
message EntryList {
Expand Down
22 changes: 6 additions & 16 deletions crates/spfs/src/storage/fs/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ impl FSRepository {
fn tags_root(&self) -> PathBuf {
let mut tags_root = self.root().join("tags");
if let Some(tag_namespace) = self.get_tag_namespace() {
for (index, component) in tag_namespace.components().enumerate() {
for component in tag_namespace.components() {
// Assuming the tag namespace is only made up of `Normal`
// elements (validated elsewhere).
let Component::Normal(component) = component else {
continue;
};

// Add a suffix in the form of `"#ns.<depth>"` to distinguish
// tag namespace subdirectories from normal tag subdirectories,
// and to disambiguate some tag namespaces having a common
// directory prefix with another namespace.
tags_root = tags_root.join(format!("{}#ns.{index}", component.to_string_lossy()));
// Add a suffix in the form of `"#ns"` to distinguish
// tag namespace subdirectories from normal tag subdirectories.
tags_root = tags_root.join(format!("{}#ns", component.to_string_lossy()));
}
}
tags_root
Expand Down Expand Up @@ -92,16 +90,8 @@ impl TagStorage for FSRepository {
} else if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) {
path.file_name().map(|s| {
let s = s.to_string_lossy();
match s.split_once("#ns.") {
Some((name, depth)) => Ok(EntryType::Namespace {
name: name.to_owned(),
depth: depth.parse().map_err(|err| {
Error::String(format!(
"Failed to parse depth number in tag namespace '{}': {err}",
s
))
})?,
}),
match s.split_once("#ns") {
Some((name, _)) => Ok(EntryType::Namespace(name.to_owned())),
None => Ok(EntryType::Folder(s.to_string())),
}
})
Expand Down
6 changes: 3 additions & 3 deletions crates/spfs/src/storage/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ mod tag_test;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum EntryType {
Folder(String),
Namespace { name: String, depth: u64 },
Namespace(String),
Tag(String),
}

impl AsRef<str> for EntryType {
fn as_ref(&self) -> &str {
match self {
Self::Folder(s) => s,
Self::Namespace { name, .. } => name,
Self::Namespace(s) => s,
Self::Tag(s) => s,
}
}
Expand All @@ -42,7 +42,7 @@ impl Display for EntryType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
match self {
EntryType::Folder(e) => f.pad(format!("{e}/").as_str()),
EntryType::Namespace { name, depth } => f.pad(format!("{name}#ns.{depth}/").as_str()),
EntryType::Namespace(e) => f.pad(format!("{e}#ns/").as_str()),
EntryType::Tag(e) => f.pad(e),
}
}
Expand Down
8 changes: 1 addition & 7 deletions crates/spfs/src/storage/tag_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,7 @@ async fn test_tag_in_namespace(
.collect::<Result<Vec<_>>>()
.await
.unwrap();
assert_eq!(
tags,
vec![EntryType::Namespace {
name: namespace_name.to_string(),
depth: 0
}]
);
assert_eq!(tags, vec![EntryType::Namespace(namespace_name.to_string())]);
}

#[rstest]
Expand Down

0 comments on commit d870a5f

Please sign in to comment.