Skip to content

Commit

Permalink
Ignore gitignored files (#531)
Browse files Browse the repository at this point in the history
Co-authored-by: nebulatgs <[email protected]>
  • Loading branch information
Milo123459 and nebulatgs authored Sep 10, 2022
1 parent 4377ac2 commit d18a176
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ textwrap = { default-features = false, version = "0.15.0" }
cargo_toml = "0.11.6"
rand = "0.8.5"
path-slash = "0.2.1"
ignore = "0.4.18"

[dev-dependencies]
dotenv-parser = "0.1.3"
Expand Down
19 changes: 12 additions & 7 deletions src/nixpacks/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use anyhow::{bail, Context, Result};
use globset::Glob;
use path_slash::PathBufExt;
use regex::Regex;
use serde::de::DeserializeOwned;
use std::collections::BTreeMap;
use std::ffi::OsStr;
use std::path::Path;
use std::{env, fs, path::PathBuf};
use walkdir::{DirEntry, WalkDir};

use anyhow::{bail, Context, Result};
use globset::Glob;
use ignore::{DirEntry, WalkBuilder};
use regex::Regex;
use serde::de::DeserializeOwned;

pub type StaticAssets = BTreeMap<String, String>;

Expand Down Expand Up @@ -74,11 +76,14 @@ impl App {
None => return Ok(Vec::new()),
};

let walker = WalkDir::new(&self.source);
let walker = WalkBuilder::new(&self.source)
// this includes hidden directories & files
.hidden(false)
.sort_by_file_name(OsStr::cmp)
.build();
let glob = Glob::new(pattern_str)?.compile_matcher();

let relative_paths = walker
.sort_by_file_name()
.into_iter()
.filter_map(Result::ok) // remove bad ones
.map(DirEntry::into_path) // convert to paths
Expand Down
41 changes: 23 additions & 18 deletions src/nixpacks/files.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
use anyhow::Result;
use ignore::WalkBuilder;
use std::{fs, io, path::Path};
use walkdir::WalkDir;

pub fn recursive_copy_dir<T: AsRef<Path>, Q: AsRef<Path>>(source: T, dest: Q) -> Result<()> {
let walker = WalkDir::new(&source).follow_links(false);
let walker = WalkBuilder::new(&source)
.follow_links(false)
// this includes hidden directories & files
.hidden(false)
.build();
for entry in walker {
let entry = entry?;
if let Some(file_type) = entry.file_type() {
let from = entry.path();
let to = dest.as_ref().join(from.strip_prefix(&source)?);

let from = entry.path();
let to = dest.as_ref().join(from.strip_prefix(&source)?);

// create directories
if entry.file_type().is_dir() {
if let Err(e) = fs::create_dir(to) {
match e.kind() {
io::ErrorKind::AlreadyExists => {}
_ => return Err(e.into()),
// create directories
if file_type.is_dir() {
if let Err(e) = fs::create_dir(to) {
match e.kind() {
io::ErrorKind::AlreadyExists => {}
_ => return Err(e.into()),
}
}
}
}
// copy files
else if entry.file_type().is_file() {
fs::copy(&from, &to)?;
// replace CRLF with LF
if let Ok(data) = fs::read_to_string(from) {
fs::write(&to, data.replace("\r\n", "\n"))?;
// copy files
else if file_type.is_file() {
fs::copy(&from, &to)?;
// replace CRLF with LF
if let Ok(data) = fs::read_to_string(from) {
fs::write(&to, data.replace("\r\n", "\n"))?;
}
}
}
}
Expand Down

0 comments on commit d18a176

Please sign in to comment.