Skip to content

Commit

Permalink
improve work with subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
wasm-forge committed Feb 27, 2024
1 parent 363d28c commit 2167c60
Show file tree
Hide file tree
Showing 10 changed files with 903 additions and 264 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stable-fs"
version = "0.1.12"
version = "0.1.13"
edition = "2021"
description = "A Simple File system implementing WASI endpoints and using the stable structures of the Internet Computer"
keywords = ["ic", "internet-computer", "file-system"]
Expand Down
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub enum Error {
NotFound,
InvalidOffset,
InvalidFileType,
InvalidFileName,
InvalidFileDescriptor,
InvalidBufferLength,
InvalidOpenFlags,
Expand Down
16 changes: 9 additions & 7 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
dir::Dir,
fd::{FdEntry, FdTable},
file::File,
structure_helpers::{create_hard_link, find_node, rm_dir_entry},
},
storage::{
types::{DirEntry, DirEntryIndex, FileSize, FileType, Metadata, Node},
Expand All @@ -21,7 +22,7 @@ pub use crate::runtime::types::{
pub struct FileSystem {
root_fd: Fd,
fd_table: FdTable,
storage: Box<dyn Storage>,
pub storage: Box<dyn Storage>,
}

impl FileSystem {
Expand Down Expand Up @@ -281,7 +282,7 @@ impl FileSystem {
// Get metadata of a file with name `path` in a given folder.
pub fn open_metadata(&self, parent: Fd, path: &str) -> Result<Metadata, Error> {
let dir = self.get_dir(parent)?;
let node = dir.find_node(path, self.storage.as_ref())?;
let node = find_node(dir.node, path, self.storage.as_ref())?;
self.storage.get_metadata(node)
}

Expand All @@ -296,7 +297,7 @@ impl FileSystem {
) -> Result<Fd, Error> {
let dir = self.get_dir(parent)?;

match dir.find_node(path, self.storage.as_ref()) {
match find_node(dir.node, path, self.storage.as_ref()) {
Ok(node) => self.open(node, stat, flags),
Err(Error::NotFound) => {
if !flags.contains(OpenFlags::CREATE) {
Expand Down Expand Up @@ -393,9 +394,9 @@ impl FileSystem {
let src_dir = self.get_dir(old_fd)?;
let dst_dir = self.get_dir(new_fd)?;

dst_dir.create_hard_link(new_path, &src_dir, old_path, false, self.storage.as_mut())?;
create_hard_link(dst_dir.node, new_path, src_dir.node, old_path, false, self.storage.as_mut())?;

let node = dst_dir.find_node(new_path, self.storage.as_ref())?;
let node = find_node(dst_dir.node, new_path, self.storage.as_ref())?;

self.open(node, FdStat::default(), OpenFlags::empty())
}
Expand All @@ -412,10 +413,11 @@ impl FileSystem {
let dst_dir = self.get_dir(new_fd)?;

// create a new link
dst_dir.create_hard_link(new_path, &src_dir, old_path, true, self.storage.as_mut())?;
create_hard_link(dst_dir.node, new_path, src_dir.node, old_path, true, self.storage.as_mut())?;

// now unlink the older version
let (node, _metadata) = src_dir.rm_entry(
let (node, _metadata) = rm_dir_entry(
src_dir.node,
old_path,
None,
self.fd_table.node_refcount(),
Expand Down
1 change: 1 addition & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod dir;
pub mod fd;
pub mod file;
pub mod structure_helpers;
pub mod types;
Loading

0 comments on commit 2167c60

Please sign in to comment.