Skip to content

Commit a89864a

Browse files
ZexbeJoshua Nelson
authored and
Joshua Nelson
committed
Normalize windows paths
1 parent 2241e06 commit a89864a

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ handlebars-iron = "0.22"
4848
params = "0.6"
4949
staticfile = { version = "0.4", features = [ "cache" ] }
5050

51+
[target.'cfg(windows)'.dependencies]
52+
path-slash = "0.1.1"
53+
5154
[dependencies.postgres]
5255
version = "0.15"
5356
features = [ "with-time", "with-rustc-serialize" ]

src/db/file.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
163163

164164
use std::collections::HashMap;
165165
let mut file_paths_and_mimes: HashMap<PathBuf, String> = HashMap::new();
166-
167166
use futures::future::Future;
168167

169168
let mut rt = ::tokio::runtime::Runtime::new().unwrap();
@@ -188,8 +187,13 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
188187
};
189188
let mut content: Vec<u8> = Vec::new();
190189
file.read_to_end(&mut content)?;
191-
let bucket_path = Path::new(prefix).join(&file_path)
192-
.into_os_string().into_string().unwrap();
190+
191+
let bucket_path = Path::new(prefix).join(&file_path);
192+
193+
#[cfg(windows)] // On windows, we need to normalize \\ to / so the route logic works
194+
let bucket_path = path_slash::PathBufExt::to_slash(&bucket_path).unwrap();
195+
#[cfg(not(windows))]
196+
let bucket_path = bucket_path.into_os_string().into_string().unwrap();
193197

194198
let mime = {
195199
let mime = cookie.buffer(&content)?;

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ extern crate tokio;
4141
extern crate systemstat;
4242
extern crate rustwide;
4343
extern crate tempdir;
44+
45+
#[cfg(windows)]
46+
extern crate path_slash;
47+
4448
#[cfg(test)]
4549
extern crate once_cell;
4650

0 commit comments

Comments
 (0)