Skip to content

Commit 159138c

Browse files
committed
Support ignoring files/folders and show error message for subdirs
- Previously subdirs were not supported and would cause an 'access denied' error
1 parent 547e17e commit 159138c

File tree

3 files changed

+221
-0
lines changed

3 files changed

+221
-0
lines changed

Cargo.lock

Lines changed: 189 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ authors = ["Jáchym Toušek <enumag@gmail.com>"]
55

66
[dependencies]
77
Inflector = "*"
8+
log = "0.4.20"
9+
simplelog = "0.12.1"

src/main.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
extern crate inflector;
2+
extern crate log;
3+
extern crate simplelog;
24

35
use std::env;
46
use std::process::{Command, ExitCode};
@@ -7,8 +9,18 @@ use std::path::Path;
79
use std::collections::HashMap;
810
use std::process;
911
use inflector::Inflector;
12+
use log::*;
13+
use simplelog::{TermLogger, TerminalMode, ColorChoice,Config};
1014

1115
fn main() -> ExitCode {
16+
TermLogger::init(
17+
LevelFilter::Trace,
18+
Config::default(),
19+
TerminalMode::Stdout,
20+
ColorChoice::Auto,
21+
)
22+
.expect("Failed to init logger");
23+
1224
let args: Vec<String> = env::args().collect();
1325
let chapter = &args[1];
1426
let unity = &args[2];
@@ -281,6 +293,24 @@ fn copy_files(from: &str, to: &str) {
281293
println!("Copying files from {}", from);
282294
for entry in fs::read_dir(from).expect("Can't read directory") {
283295
let path = entry.unwrap().path();
296+
297+
// Ignore paths starting with '.ignore' and emit warning
298+
if let Some(name) = path.file_name() {
299+
let name = name.to_os_string();
300+
if name.to_string_lossy().to_lowercase().starts_with(".ignore")
301+
{
302+
warn!("Skipping path {:?} as it starts with '.ignore'", path);
303+
continue;
304+
}
305+
}
306+
307+
// For now, subdirectories are not supported
308+
if path.is_dir()
309+
{
310+
error!("Found subdirectory at {:?} - Subdirectories not supported, please remove or prepend with 'IGNORE' to ignore.", path);
311+
panic!("Exiting due to unexpected subdirectory");
312+
}
313+
284314
let to_path = format!("{}/{}", to, path.file_name().unwrap().to_str().unwrap());
285315
println!("Copying File {} -> {}", path.to_string_lossy(), to_path);
286316
fs::copy(&path, to_path).expect("Unable to copy");

0 commit comments

Comments
 (0)