Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit b1fc71e

Browse files
committed
Create data directory if it does not exist
Alfred provides workflows with an environment variable to a data directory, but does not create this directory for a workflow. This causes alfred-gitignore to fail for new installations. When a new repository is initialized, the directory is created now if it does not exist yet.
1 parent 3bf08da commit b1fc71e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and [Rust](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution
1010

1111
## [Unreleased]
1212

13+
### Fixed
14+
15+
- Fix `Path to repository does not exist` error for fresh installations ([#4](https://github.com/jdno/alfred-gitignore/issues/4))
16+
1317
## [2.0.0] - 2020-04-26
1418

1519
### Changed

src/repository.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use getset::Getters;
22
use std::env::temp_dir;
3-
use std::fs::{read_dir, File};
3+
use std::fs::{create_dir, read_dir, File};
44
use std::io::{copy, Error, ErrorKind};
55
use std::path::PathBuf;
66
use zip::ZipArchive;
@@ -56,10 +56,7 @@ impl Repository {
5656
/// repository, or an error that explains why the repository could not be initialized.
5757
pub fn new(path: PathBuf) -> Result<Self, Error> {
5858
if !path.exists() {
59-
return Err(Error::new(
60-
ErrorKind::NotFound,
61-
"Path to repository does not exist",
62-
));
59+
create_dir(&path)?;
6360
}
6461

6562
Ok(Repository { path })
@@ -188,8 +185,7 @@ mod tests {
188185
use crate::testing::initialize_repository;
189186
use mockito::{mock, Mock};
190187
use std::fs::{remove_file, File};
191-
use std::io::{ErrorKind, Write};
192-
use std::path::PathBuf;
188+
use std::io::Write;
193189
use tempdir::TempDir;
194190

195191
const ARCHIVE: &[u8] = include_bytes!("../tests/files/gitignore-master.zip");
@@ -212,9 +208,13 @@ mod tests {
212208

213209
#[test]
214210
fn new_with_empty_path() {
215-
let repository = Repository::new(PathBuf::from("does-not-exist"));
211+
let directory = TempDir::new("new_with_existing_path").unwrap();
212+
let path = directory.path().join("does-not-exist");
213+
214+
let repository = Repository::new(path.clone());
216215

217-
assert_eq!(ErrorKind::NotFound, repository.unwrap_err().kind());
216+
assert!(repository.is_ok());
217+
assert!(path.exists());
218218
}
219219

220220
#[test]

0 commit comments

Comments
 (0)