添加rename的support
This commit is contained in:
parent
017c52ce13
commit
53d62dc0a9
|
@ -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;
|
||||
}
|
|
@ -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