WIP: Add tar utility
This commit is contained in:
@@ -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)?;
|
||||
|
||||
@@ -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())?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user