添加rename的support

This commit is contained in:
Ekko.bao 2024-07-16 08:00:29 +08:00
parent 017c52ce13
commit 53d62dc0a9
3 changed files with 36 additions and 6 deletions

View File

@ -39,6 +39,7 @@ service LwsVfs {
rpc freleasedir(releasedir) returns (releasedir) {}
rpc fcreate(create) returns (create) {}
rpc funlink(unlink) returns (unlink) {}
rpc frename(rename) returns (rename) {}
}
// The request message containing the user's name.
@ -202,3 +203,9 @@ message unlink{
string path = 1;
int32 ret = 15;
}
message rename {
string path = 1;
string new = 2;
int32 ret = 15;
}

View File

@ -420,6 +420,11 @@ impl FSImpl {
Ok(-1)
}
}
/** Rename a file */
pub fn frename(&self, path: &String, new: &String) -> Result<i32, Box<dyn Error>> {
fs::rename(path, new)?;
Ok(0)
}
}
#[test]

View File

@ -2,7 +2,7 @@
use lws_vfs::lws_vfs_server::LwsVfs;
use lws_vfs::{
Access, Chown, FileInfo, Flush, Fstat, Getattr, Getxattr, HelloReply, HelloRequest, Mkdir,
Open, Read, Readdir, Release, Rmdir, Setxattr, Truncate, Utimens, Write, Create, Unlink, Opendir, Releasedir
Open, Read, Readdir, Release, Rmdir, Setxattr, Truncate, Utimens, Write, Create, Unlink, Opendir, Releasedir, Rename
};
use self::fs_impl::FSImpl;
use serde_json::{self, Value};
@ -482,4 +482,22 @@ impl LwsVfs for LwsVfsIns {
};
Ok(Response::new(reply))
}
async fn frename(&self, request: Request<Rename>) -> Result<Response<Rename>, Status> {
let request = request.into_inner();
let from = &self.lpath(&request.path);
let to = &self.lpath(&request.new);
let ret = match self.fs.frename(from, to) {
Ok(ret) => ret,
Err(e) => {
println!("Error: rename file[{}]: {:?}", from, e);
-1
}
};
let reply = Rename {
ret,
..Rename::default()
};
Ok(Response::new(reply))
}
}