Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve existing .gitignore file in out directory #985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use failure;
use std::fs;
use std::fs::OpenOptions;
use std::io::{ErrorKind, Write};
use std::path::{Path, PathBuf};
use std::time::Duration;
use walkdir::WalkDir;
Expand Down Expand Up @@ -38,8 +40,20 @@ fn find_manifest_from_cwd() -> Result<PathBuf, failure::Error> {
/// Construct our `pkg` directory in the crate.
pub fn create_pkg_dir(out_dir: &Path) -> Result<(), failure::Error> {
fs::create_dir_all(&out_dir)?;
fs::write(out_dir.join(".gitignore"), "*")?;
Ok(())

let file = OpenOptions::new()
.write(true)
.create_new(true)
.open(out_dir.join(".gitignore"))
.map(|mut f| f.write_all(b"*"));

match file {
Ok(_) => Ok(()),
Err(e) => match e.kind() {
ErrorKind::AlreadyExists => Ok(()),
_ => Err(e.into()),
},
}
}

/// Locates the pkg directory from a specific path
Expand Down