diff options
| author | Mel <einebeere@gmail.com> | 2021-10-02 19:55:01 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-10-02 19:55:01 +0200 |
| commit | 55da5ae8cf731c768d6cc580693068e64234a4af (patch) | |
| tree | 9024bf8c315f1c150a468db6791acbeec2907601 /src/actions/create.rs | |
| parent | c1eccadf76ca7625d8cff9a52480168aab876e62 (diff) | |
| download | ka-55da5ae8cf731c768d6cc580693068e64234a4af.tar.zst ka-55da5ae8cf731c768d6cc580693068e64234a4af.zip | |
Use filesystem abstraction throughout Ka.
Diffstat (limited to 'src/actions/create.rs')
| -rw-r--r-- | src/actions/create.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/actions/create.rs b/src/actions/create.rs index 472cbe3..20dbff7 100644 --- a/src/actions/create.rs +++ b/src/actions/create.rs @@ -1,26 +1,23 @@ -use std::fs::{self, File}; - +use crate::{actions::update, files::Locations, filesystem::Fs, history::RepositoryHistory}; use anyhow::Result; -use crate::{actions::update, files::Locations, history::RepositoryHistory}; - use super::ActionOptions; -pub fn create(command_options: ActionOptions) -> Result<()> { +pub fn create(command_options: ActionOptions, fs: &mut impl Fs) -> Result<()> { let locations = Locations::from(&command_options); + // FIXME: Re-add old repository deletion. + // if locations.ka_path.exists() { + // fs::remove_dir_all(locations.ka_path.as_path())?; + // } - if locations.ka_path.exists() { - fs::remove_dir_all(locations.ka_path.as_path())?; - } - - fs::create_dir(&locations.ka_path)?; - fs::create_dir(&locations.ka_files_path)?; + // fs::create_dir(&locations.ka_path)?; + // fs::create_dir(&locations.ka_files_path)?; - let mut index_file = File::create(locations.get_repository_index())?; + let mut index_file = fs.create_file(&locations.get_repository_index_path())?; let empty_history = RepositoryHistory::default(); - empty_history.write_to_file(&mut index_file)?; + empty_history.write_to_file(fs, &mut index_file)?; - update(command_options)?; + update(command_options, fs)?; Ok(()) } |
