Skip to content

Commit 3985d0c

Browse files
Percent encode toolchain string when used in a path
1 parent 3c25c49 commit 3985d0c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/dirs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub(crate) fn crate_source_dir(ex: &Experiment, tc: &Toolchain, krate: &Crate) -
4343
EXPERIMENT_DIR
4444
.join(&ex.name)
4545
.join("sources")
46-
.join(tc.to_string())
46+
.join(tc.to_path_component())
4747
.join(krate.id())
4848
}

src/toolchain.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Toolchain {
101101
dir = dir.join("shared");
102102
}
103103

104-
dir.join(self.to_string())
104+
dir.join(self.to_path_component())
105105
}
106106

107107
pub fn prep_offline_registry(&self) -> Fallible<()> {
@@ -121,6 +121,12 @@ impl Toolchain {
121121
// is ready
122122
Ok(())
123123
}
124+
125+
pub fn to_path_component(&self) -> String {
126+
use url::percent_encoding::utf8_percent_encode as encode;
127+
128+
encode(&self.to_string(), utils::fs::FILENAME_ENCODE_SET).to_string()
129+
}
124130
}
125131

126132
impl fmt::Display for Toolchain {

src/utils/fs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ use crate::prelude::*;
22
use crate::utils::try_hard_limit;
33
use std::fs;
44
use std::path::{Path, PathBuf};
5+
use url::percent_encoding::SIMPLE_ENCODE_SET;
56
use walkdir::{DirEntry, WalkDir};
67

8+
url::define_encode_set! {
9+
/// The set of characters which cannot be used in a [filename on Windows][windows].
10+
///
11+
/// [windows]: https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#naming-conventions
12+
pub FILENAME_ENCODE_SET = [SIMPLE_ENCODE_SET] | { '<', '>', ':', '"', '/', '\\', '|', '?', '*' }
13+
}
14+
715
pub(crate) fn try_canonicalize<P: AsRef<Path>>(path: P) -> PathBuf {
816
fs::canonicalize(&path).unwrap_or_else(|_| path.as_ref().to_path_buf())
917
}

0 commit comments

Comments
 (0)