Skip to content

Commit 55dda79

Browse files
committed
Fix issues after rebasing to vfs 0.5.0
1 parent f3fa875 commit 55dda79

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

examples/https_fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> vfs::VfsResult<()> {
4444
let root = root.join("example.txt")?;
4545

4646
// make sure that file exists
47-
if !root.exists() {
47+
if !root.exists()? {
4848
root.create_file()?;
4949
}
5050

src/impls/https.rs

+29-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
//! perceived as a liability.
3333
//! - Write a HttpsFS version, which can be compiled to WebAssembly
3434
//! - Consider to provide an non-blocking version of HttpsFS
35-
//! - Change result of FileSystem::exists() from bool to VfsResult<bool>
3635
//! - Do version check after connecting to a HttpsFSServer
3736
//! - Do not expose reqwest::Certificate and rustls::Certificate via the API
3837
//! - Look for some unwrap(), which can be removed.
@@ -185,7 +184,7 @@ struct CommandRemoveDir {
185184

186185
#[derive(Debug, Deserialize, Serialize)]
187186
enum CommandResponse {
188-
Exists(bool),
187+
Exists(Result<bool, String>),
189188
Metadata(Result<CmdMetadata, String>),
190189
CreateFile(CommandResponseCreateFile),
191190
RemoveFile(Result<(), String>),
@@ -654,7 +653,13 @@ impl<T: FileSystem> HttpsFSServer<T> {
654653

655654
fn handle_command(command: &Command, file_system: &dyn FileSystem) -> CommandResponse {
656655
match command {
657-
Command::Exists(param) => CommandResponse::Exists(file_system.exists(&param.path)),
656+
Command::Exists(param) => CommandResponse::Exists({
657+
let result = file_system.exists(&param.path);
658+
match result {
659+
Ok(val) => Ok(val),
660+
Err(e) => Err(format!("{:?}", e)),
661+
}
662+
}),
658663
Command::Metadata(param) => CommandResponse::Metadata(meta_res_convert_vfs_cmd(
659664
file_system.metadata(&param.path),
660665
)),
@@ -691,7 +696,12 @@ impl<T: FileSystem> HttpsFSServer<T> {
691696
}
692697

693698
fn write(cmd: &CommandWrite, file_system: &dyn FileSystem) -> Result<usize, String> {
694-
if !file_system.exists(&cmd.path) {
699+
let exist = file_system.exists(&cmd.path);
700+
if let Err(e) = exist {
701+
return Err(format!("{:?}", e));
702+
}
703+
let exist = exist.unwrap();
704+
if !exist {
695705
println!("WARN: Tried to write to non existing file.");
696706
return Err(String::from("File does not exists!"));
697707
}
@@ -1112,7 +1122,7 @@ impl FileSystem for HttpsFS {
11121122
}
11131123

11141124
fn open_file(&self, path: &str) -> VfsResult<Box<dyn SeekAndRead>> {
1115-
if !self.exists(path) {
1125+
if !self.exists(path)? {
11161126
return Err(VfsError::FileNotFound {
11171127
path: path.to_string(),
11181128
})?;
@@ -1176,22 +1186,28 @@ impl FileSystem for HttpsFS {
11761186
}
11771187
}
11781188

1179-
fn exists(&self, path: &str) -> bool {
1189+
fn exists(&self, path: &str) -> VfsResult<bool> {
11801190
// TODO: Add more logging
11811191
// TODO: try to change return type to VfsResult<bool>
11821192
// At the moment 'false' does not mean, that the file either does not exist
11831193
// or that an error has occurred. An developer does not expect this.
11841194
let req = Command::Exists(CommandExists {
11851195
path: String::from(path),
11861196
});
1187-
let result = self.exec_command(&req);
1188-
if let Err(e) = result {
1189-
println!("Error: {}", e);
1190-
return false;
1191-
}
1192-
match result.unwrap() {
1197+
let result = self.exec_command(&req)?;
1198+
let result = match result {
11931199
CommandResponse::Exists(value) => value,
1194-
_ => false,
1200+
_ => {
1201+
return Err(VfsError::Other {
1202+
message: String::from("Result doesn't match the request!"),
1203+
});
1204+
}
1205+
};
1206+
match result {
1207+
Err(e) => Err(VfsError::Other {
1208+
message: format!("{:?}", e),
1209+
}),
1210+
Ok(val) => Ok(val),
11951211
}
11961212
}
11971213

0 commit comments

Comments
 (0)