Skip to content

Commit 2ff556a

Browse files
committed
fuse rename
todo: - write - truncate - unlink (rm)
1 parent d072d5d commit 2ff556a

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/fuse/core.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,20 @@ impl FuseHandler<PathBuf> for OkuFs {
372372

373373
fn rename(
374374
&self,
375-
req: &RequestInfo,
375+
_req: &RequestInfo,
376376
parent_id: PathBuf,
377377
name: &OsStr,
378378
newparent: PathBuf,
379379
newname: &OsStr,
380380
flags: RenameFlags,
381381
) -> FuseResult<()> {
382-
self.get_inner()
383-
.rename(req, parent_id, name, newparent, newname, flags)
382+
let parent_id = normalise_path(&parent_id);
383+
debug!("[rename] parent_id = {parent_id:?}, name = {name:?}, newparent = {newparent:?}, newname = {newname:?}, flags = {flags:?}");
384+
self.rename(parent_id, name, newparent, newname)
385+
.map_err(|e| {
386+
error!("[rename]: {e}");
387+
PosixError::new(ErrorKind::FileNotFound, e.to_string())
388+
})
384389
}
385390

386391
fn setattr(

src/fuse/methods.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use log::info;
66
use miette::IntoDiagnostic;
77
use std::ffi::OsStr;
88
use std::ffi::OsString;
9+
use std::fs::FileType;
910
use std::io::Read;
1011
use std::io::Seek;
1112
use std::path::PathBuf;
@@ -107,4 +108,53 @@ impl OkuFs {
107108
FUSEOpenResponseFlags::empty(),
108109
))
109110
}
111+
112+
pub(super) fn rename(
113+
&self,
114+
parent_id: PathBuf,
115+
name: &OsStr,
116+
newparent: PathBuf,
117+
newname: &OsStr,
118+
) -> miette::Result<()> {
119+
let old_path = parent_id.join(name);
120+
let path_type = self
121+
.handle
122+
.block_on(async { self.is_file_or_directory(&old_path).await })?;
123+
let new_path = newparent.join(newname);
124+
let (old_namespace_id, old_replica_path) = parse_fuse_path(&old_path)
125+
.map(|x| x.ok_or(miette::miette!("Cannot rename root directory")))??;
126+
let (new_namespace_id, new_replica_path) = parse_fuse_path(&new_path)
127+
.map(|x| x.ok_or(miette::miette!("Cannot rename root directory")))??;
128+
match path_type {
129+
fuser::FileType::RegularFile => {
130+
let (new_hash, files_moved) = self.handle.block_on(async {
131+
self.move_file(
132+
&old_namespace_id,
133+
&old_replica_path,
134+
&new_namespace_id,
135+
&new_replica_path,
136+
)
137+
.await
138+
})?;
139+
info!("File {old_path:?} moved to {new_path:?} (files moved: {files_moved}, new hash: {new_hash})");
140+
Ok(())
141+
}
142+
fuser::FileType::Directory => {
143+
let (new_hashes, files_moved) = self.handle.block_on(async {
144+
self.move_directory(
145+
&old_namespace_id,
146+
&old_replica_path,
147+
&new_namespace_id,
148+
&new_replica_path,
149+
)
150+
.await
151+
})?;
152+
info!("Directory {old_path:?} moved to {new_path:?} (files moved: {files_moved}, new hashes: {new_hashes:?})");
153+
Ok(())
154+
}
155+
_ => Err(miette::miette!(
156+
"File system entry type {path_type:?} at {old_path:?} not supported"
157+
)),
158+
}
159+
}
110160
}

0 commit comments

Comments
 (0)