WIP: Add tar utility

This commit is contained in:
2025-10-16 10:42:41 +03:00
parent 312458b8f0
commit a87c8a7ee2
18 changed files with 712 additions and 33 deletions
+12
View File
@@ -503,6 +503,18 @@ impl Node {
}
}
impl DirectoryData {
fn contains(&self, node: &NodeRef, name: &Filename) -> bool {
{
let cache = self.children.lock();
if cache.iter().any(|(n, _)| n == name) {
return true;
}
}
self.imp.contains(node, name)
}
}
impl HardlinkData {
fn target(&self, link: &NodeRef) -> Result<NodeRef, Error> {
let target = self.imp.target(link)?;
+3
View File
@@ -110,6 +110,9 @@ impl Node {
/// Creates an entry within a directory with given [CreateInfo].
pub fn create(self: &NodeRef, info: CreateInfo, check: AccessToken) -> Result<NodeRef, Error> {
let directory = self.as_directory()?;
if directory.contains(self, info.name) {
return Err(Error::AlreadyExists);
}
let node = directory.imp.create_node(self, &info)?;
self.create_node(node.clone(), info.name, check.clone())?;
+7
View File
@@ -149,6 +149,13 @@ pub trait DirectoryImpl: CommonImpl {
Err(Error::NotImplemented)
}
fn contains(&self, node: &NodeRef, name: &Filename) -> bool {
match self.lookup(node, name) {
Ok(_) => true,
Err(_) => false,
}
}
/// Returns the "length" of the directory in entries
fn len(&self, node: &NodeRef) -> Result<usize, Error> {
let _ = node;
+3 -6
View File
@@ -32,12 +32,9 @@ impl Node {
let directory = self.as_directory()?;
let mut children = directory.children.lock();
// TODO check if an entry already exists with such name
// if children.contains_key(&name) {
// log::warn!("Directory cache already contains an entry: {:?}", name);
// return Err(Error::AlreadyExists);
// }
if children.iter().any(|(n, _)| name == *n) {
return Err(Error::AlreadyExists);
}
assert!(child.parent.replace(Some(self.clone())).is_none());
children.push((name, child));