Skip to content

Commit 8d3001f

Browse files
committed
Accepting only empty dirs
1 parent fd3aa2a commit 8d3001f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/project_maker.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,24 @@ pub fn setup_dir(project: &mut ProjectConfig) -> PathBuf {
135135
print_err("The given path is a file. You must either use an empty directory or a non existing one");
136136
return setup_dir(project);
137137
}
138+
139+
match path.read_dir() {
140+
Ok(reader) => {
141+
if reader.count() != 0 {
142+
print_err("The project directory must be empty.");
143+
return setup_dir(project);
144+
}
145+
},
146+
Err(err) => {
147+
print_err(format!("Failed to read directory: {}. Consider changing the path", err));
148+
return setup_dir(project);
149+
}
150+
}
138151
} else {
139152
match fs::create_dir_all(path) {
140153
Ok(()) => {},
141154
Err(err) => {
142-
print_err(format!("Failed to create directories: {}", err));
155+
print_err(format!("Failed to create directories: {}. Consider changing the path", err));
143156
return setup_dir(project);
144157
}
145158
}

0 commit comments

Comments
 (0)