Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Absolute file URLs on Windows #60

Closed
anlumo opened this issue Dec 6, 2019 · 5 comments
Closed

Absolute file URLs on Windows #60

anlumo opened this issue Dec 6, 2019 · 5 comments

Comments

@anlumo
Copy link

anlumo commented Dec 6, 2019

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
Copy link
Contributor

burmecia commented Dec 7, 2019

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

@anlumo
Copy link
Author

anlumo commented Dec 10, 2019

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
Copy link
Contributor

burmecia commented Dec 10, 2019

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
Copy link
Author

anlumo commented Dec 10, 2019

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
Copy link
Contributor

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.

burmecia added a commit that referenced this issue Dec 13, 2019
burmecia added a commit that referenced this issue Dec 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants