Skip to content

Commit 0d2f0bb

Browse files
committed
feat: add warning for protected dirs '.' and '..'
1 parent f847d52 commit 0d2f0bb

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Mustafa <[email protected]>"]
33
edition = "2018"
44
name = "renom"
5-
version = "1.2.0"
5+
version = "1.3.0"
66
description = "A simple program to rename Unreal Engine projects."
77
keywords = ["gamedev", "ue4", "ue5", "unreal_engine", "rename"]
88
categories = [

src/workflows/rename_project/interactive.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ pub fn get_params_from_user() -> Result<Params, String> {
1616

1717
fn get_project_root_from_user() -> Result<PathBuf, String> {
1818
Text::new("Project root directory path:")
19+
.with_validator(validate_project_root_is_not_special)
1920
.with_validator(validate_project_root_is_dir)
2021
.with_validator(validate_project_root_contains_project_descriptor)
2122
.prompt()
2223
.map(|project_root| PathBuf::from(project_root))
2324
.map_err(|err| err.to_string())
2425
}
2526

27+
fn validate_project_root_is_not_special(project_root: &str) -> Result<Validation, CustomUserError> {
28+
match project_root {
29+
"." => Ok(Validation::Invalid("Provided path '.' is protected".into())),
30+
".." => Ok(Validation::Invalid(
31+
"Provided path '..' is protected".into(),
32+
)),
33+
_ => Ok(Validation::Valid),
34+
}
35+
}
36+
2637
fn validate_project_root_is_dir(project_root: &str) -> Result<Validation, CustomUserError> {
2738
match PathBuf::from(project_root).is_dir() {
2839
true => Ok(Validation::Valid),

src/workflows/rename_project/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn rename_project(params: Params) -> Result<(), String> {
5757
}
5858

5959
fn validate_params(params: &Params) -> Result<(), String> {
60+
validate_project_root_is_not_special(&params.project_root)?;
6061
validate_project_root_is_dir(&params.project_root)?;
6162
validate_project_root_contains_project_descriptor(&params.project_root)?;
6263
let project_name = detect_project_name(&params.project_root)?;
@@ -67,6 +68,14 @@ fn validate_params(params: &Params) -> Result<(), String> {
6768
Ok(())
6869
}
6970

71+
fn validate_project_root_is_not_special(project_root: &Path) -> Result<(), String> {
72+
match project_root {
73+
path if path == Path::new(".") => Err("project root cannot be '.'".into()),
74+
path if path == Path::new("..") => Err("project root cannot be '..'".into()),
75+
_ => Ok(()),
76+
}
77+
}
78+
7079
fn validate_project_root_is_dir(project_root: &Path) -> Result<(), String> {
7180
match project_root.is_dir() {
7281
true => Ok(()),

0 commit comments

Comments
 (0)