zboxfs / zbox

Zero-details, privacy-focused in-app file system.
https://zbox.io/fs/
Apache License 2.0
1.54k stars 76 forks source link

Absolute file URLs on Windows #60

Closed anlumo closed 4 years ago

anlumo commented 4 years ago

I'm able to use the file storage on Windows 10 using urls like file://../data/foo, but file://D:/data/foo fails on the open call with the following error message:

thread 'main' panicked at 'opening archive failed: Io(Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." })', src\libcore\result.rs:1189:5

I'm generating the file URLs using Url::from_file_path, so the syntax should be ok. I can also paste this URL into Chrome and opens the folder view.

burmecia commented 4 years ago

Can you share your code? I've tested on Windows 10 but cannot reproduce this issue.

anlumo commented 4 years ago

Here's a demo application: https://github.com/anlumo/zboxurls

Here's the output on my machine:

D:\zboxurls> cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target\debug\zboxurls.exe`
Opening URL: file:///D:/zboxurls/target/debug/test-fs
thread 'main' panicked at 'opening archive failed: Io(Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." })', src\libcore\result.rs:1189:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: process didn't exit successfully: `target\debug\zboxurls.exe` (exit code: 101)
burmecia commented 4 years ago

Thanks @anlumo . The reason is that url generated by Url::from_file_path is not compatible with ZboxFS URI format, which requires an OS path after file://.

For example, the required URI is like: file://C:/Users/foo bar/dir, but the URI generated by Url::from_file_path is like: file:///C:/Users/foo%20bar/dir.

A quick solution might be converting the url back to path using url.to_file_path.

let url = Url::from_file_path(&path).unwrap();
RepoOpener::new()
        .create_new(true)
        .open(&format!("file://{}", url.to_file_path().unwrap().display()), "abcdef")
        .expect("opening archive failed");
anlumo commented 4 years ago

According to Wikipedia, this is not correct. It explicitly states that the third slash is required there.

However, I noticed that your API accepts file://D:\zboxurls\target\debug\test-fs as the URL, which is horrible, but at least I can get it to work now…

burmecia commented 4 years ago

The URI used in ZboxFS is not same as the standard URI or URL, it is different according to different storage. For file storage, it looks like an URL but actually not, it is just an identifier points to a path on OS. Anyway, I will update the doc to make it more clear.