Skip to content

Commit 840b2e1

Browse files
committed
Use common escape_path
1 parent 3953a64 commit 840b2e1

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/crates/git.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@ use crate::prepare::PrepareError;
44
use crate::Workspace;
55
use failure::{Error, ResultExt};
66
use log::{info, warn};
7-
use percent_encoding::{percent_encode, AsciiSet, CONTROLS};
87
use std::path::{Path, PathBuf};
98

10-
const ENCODE_SET: AsciiSet = CONTROLS
11-
.add(b'/')
12-
.add(b'\\')
13-
.add(b'<')
14-
.add(b'>')
15-
.add(b':')
16-
.add(b'"')
17-
.add(b'|')
18-
.add(b'?')
19-
.add(b'*')
20-
.add(b' ');
21-
229
pub(super) struct GitRepo {
2310
url: String,
2411
}
@@ -54,7 +41,7 @@ impl GitRepo {
5441
workspace
5542
.cache_dir()
5643
.join("git-repos")
57-
.join(percent_encode(self.url.as_bytes(), &ENCODE_SET).to_string())
44+
.join(crate::utils::escape_path(self.url.as_bytes()))
5845
}
5946

6047
fn suppress_password_prompt_args(&self, workspace: &Workspace) -> Vec<String> {

src/crates/registry.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ impl AlternativeRegistry {
9090
}
9191

9292
fn index_folder(&self) -> String {
93-
// https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
94-
self.registry_index.as_str().replace(
95-
&['/', '\\', '<', '>', '|', '?', '*', '"', ':', '.'][..],
96-
&"-",
97-
)
93+
crate::utils::escape_path(self.registry_index.as_bytes())
9894
}
9995
}
10096

src/utils.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
use failure::Error;
22
use fs2::FileExt;
33
use log::warn;
4+
use percent_encoding::{AsciiSet, CONTROLS};
45
use std::fs::OpenOptions;
56
use std::path::{Component, Path, PathBuf, Prefix, PrefixComponent};
67

8+
const ENCODE_SET: AsciiSet = CONTROLS
9+
.add(b'/')
10+
.add(b'\\')
11+
.add(b'<')
12+
.add(b'>')
13+
.add(b':')
14+
.add(b'"')
15+
.add(b'|')
16+
.add(b'?')
17+
.add(b'*')
18+
.add(b' ');
19+
20+
pub(crate) fn escape_path(unescaped: &[u8]) -> String {
21+
percent_encoding::percent_encode(unescaped, &ENCODE_SET).to_string()
22+
}
23+
724
pub(crate) fn file_lock<T>(
825
path: &Path,
926
msg: &str,

0 commit comments

Comments
 (0)