添加rename的support
This commit is contained in:
parent
017c52ce13
commit
53d62dc0a9
|
@ -37,8 +37,9 @@ service LwsVfs {
|
|||
rpc fflush(flush) returns (flush) {}
|
||||
rpc fopendir(opendir) returns (opendir) {}
|
||||
rpc freleasedir(releasedir) returns (releasedir) {}
|
||||
rpc fcreate (create) returns (create) {}
|
||||
rpc fcreate(create) returns (create) {}
|
||||
rpc funlink(unlink) returns (unlink) {}
|
||||
rpc frename(rename) returns (rename) {}
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
|
@ -179,26 +180,32 @@ message flush {
|
|||
int32 ret = 15;
|
||||
}
|
||||
|
||||
message opendir{
|
||||
message opendir {
|
||||
string path = 1;
|
||||
file_info fi = 2;
|
||||
int32 ret = 15;
|
||||
}
|
||||
|
||||
message releasedir{
|
||||
message releasedir {
|
||||
string path = 1;
|
||||
file_info fi = 2;
|
||||
int32 ret = 15;
|
||||
}
|
||||
|
||||
message create{
|
||||
message create {
|
||||
string path = 1;
|
||||
uint32 mode = 2;
|
||||
file_info fi = 3;
|
||||
int32 ret = 15;
|
||||
}
|
||||
|
||||
message unlink{
|
||||
message unlink {
|
||||
string path = 1;
|
||||
int32 ret = 15;
|
||||
}
|
||||
|
||||
message rename {
|
||||
string path = 1;
|
||||
string new = 2;
|
||||
int32 ret = 15;
|
||||
}
|
|
@ -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]
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user