From b1e360d29b0f691006207d5156946c06f37527b2 Mon Sep 17 00:00:00 2001 From: Leon Kirschner Date: Sun, 4 Dec 2022 11:27:37 +0100 Subject: [PATCH] fixed recursive copy --- .DS_Store | Bin 6148 -> 6148 bytes .github/workflows/publish.yaml | 2 ++ .gitignore | 3 ++- clone.sh | 7 ------- kickstarter/install-mac.sh | 2 +- local.sh | 5 ----- src/lib/io.rs | 32 ++++++++++++++++++++++++++------ src/sermon.rs | 17 +++++++++++++---- src/worship.rs | 2 +- 9 files changed, 45 insertions(+), 25 deletions(-) delete mode 100644 clone.sh delete mode 100644 local.sh diff --git a/.DS_Store b/.DS_Store index 4822d6f24ab343f05d7766830a3fbe980747441c..e2350284a494ddb0c7d5a3d3874a87f9776312c6 100644 GIT binary patch literal 6148 zcmeHK!EVz)5S>jz>oh{j0i<3kS>hUnl%lFtFCk429Jn+H4uFE4SgBRV8`%y)iX!D) z{()cM%9rpjoZ!vwf@~+1I3YxLq}jLLoo9QV?O87oiQasCNYo@E2hLdAL$k$ro_)hA zX5>ClsB=haQ$&(RbiEO62dn~CfqzW_{&x51oIFZsf-m>?_xn7OBR`Tp=D9dLgSUSu zL$A!qz?@Q4;(RG_9MlD_4lxC|PD)qBcyX{1AJ9kK*_3AB1(cTJKb7Jes5+slJt<`> zqYSL1#QOectPg`Ej$}MRG-?|Ppss5kaLc_{I4-YGoi6DDs`cpwu#FtX#rsf-e$FXc zg(3-!N>Qv~K5EBgHbG`tF;?k!YplOWXXbf+^=DC-W}VJAQK{DM?d&?cPQ!UOxRQ%O z=4JD==Ou6W=%tjA|Eur$ufkw4Y(6-bapr|_kSIbp4iNJ8br_H3q9^C^I91$%o^a|; zec0SzE{{(RTkg@x>8j-}PoH#J?$e{=)vE41eDwJ2a(Eq0V|jyIVS@E$<99P}{JabK zm!44-+TdL&slu$hD)}?s?Y`03Y20lYZ1z?GtH2foxIVaW#;(D&MpZh{s4W1nhGAvs z^X~$4T!USMYmJzJ2~7oRsxVs&q3IZROd;H75J+P`~>AM)L;Mr delta 91 zcmZoMXfc=|#>CJzu~2NHo}wrt0|NsP3otMgGn6nSG86&H)QN@ajEs}HST#3`a0s(( oY_MnE%+A5j0o1iwkmEb^WPTA{PLRd}K+G`NhDUmHjK~sZ0ClMoEC2ui diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 835e4fd..f179f3e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,6 +17,8 @@ jobs: archive: tar.gz - target: x86_64-apple-darwin archive: zip + - target: armv7-unknown-linux-gnueabihf + archive: zip steps: - uses: actions/checkout@master diff --git a/.gitignore b/.gitignore index 8eb991e..a629241 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store /target .idea -tmp \ No newline at end of file +tmp +*.sh \ No newline at end of file diff --git a/clone.sh b/clone.sh deleted file mode 100644 index 42f89aa..0000000 --- a/clone.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/zsh -cargo run -- \ - -r https://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:x-oauth-basic@github.com/trpouh/test-playbook.git \ - -b main \ - --tmp-dir tmp \ - -t examples \ - -s sermon.yaml \ No newline at end of file diff --git a/kickstarter/install-mac.sh b/kickstarter/install-mac.sh index 43bb2ce..31b769c 100644 --- a/kickstarter/install-mac.sh +++ b/kickstarter/install-mac.sh @@ -23,5 +23,5 @@ psalms: - type: Hello EOT -echo "[preacher] start your first sermon with './preacher --tmp-dir ../tmp'" +echo "[preacher] start your first sermon with './preacher'" diff --git a/local.sh b/local.sh deleted file mode 100644 index 8916c8d..0000000 --- a/local.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/zsh -cargo run -- \ - --source-folder examples \ - --tmp-dir tmp \ - -s hello-sermon.yaml \ No newline at end of file diff --git a/src/lib/io.rs b/src/lib/io.rs index feece08..e1c25e0 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -28,13 +28,33 @@ pub fn clone_to_dir(repo: &str, target_dir: &str, branch: Option<&str>) { } } -pub fn copy_all_files_to_dir(source_dir: &str, target_dir: &str) { - copy_dir(&format!("{}/.", source_dir), &format!("{}/", target_dir)); +pub struct CopyOptions<'a> { + pub source_dir: &'a str, + pub target_dir: &'a str, + pub exclude: Option>, + pub without_parent_folder: Option, + pub ensure_target_exists: Option } -pub fn copy_dir(source_dir: &str, target_dir: &str) { - let mut command = Command::new("cp"); - command.arg("-r").arg(source_dir).arg(target_dir); +pub fn copy_dir(copy_options: &CopyOptions) { + + if copy_options.ensure_target_exists.unwrap_or(false) { + create_dir(copy_options.target_dir, true); + } + + let mut command = Command::new("rsync"); + + let source_dir = if copy_options.without_parent_folder.unwrap_or_else(|| false) { + format!("{}/.", copy_options.source_dir) + } else { + copy_options.source_dir.to_owned() + }; + + copy_options.exclude.as_ref().unwrap_or(&Vec::default()).iter().for_each(|dir| { + command.args(["--exclude", dir]); + }); + + command.arg("-r").arg(&source_dir).arg(copy_options.target_dir); if let Ok(mut child) = command.spawn() { let exit_status = child.wait(); @@ -43,7 +63,7 @@ pub fn copy_dir(source_dir: &str, target_dir: &str) { if status.success() { println!( "Successfully copied source dir {} to dir: {} (Status: {})", - source_dir, target_dir, status + source_dir, copy_options.target_dir, status ); } else { println!("Copying not successful"); diff --git a/src/sermon.rs b/src/sermon.rs index 0f12411..f55bebb 100644 --- a/src/sermon.rs +++ b/src/sermon.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use std::fs; use std::path::Path; -use crate::lib::io; +use crate::lib::io::{self, CopyOptions}; use crate::psalms::hello::HelloPsalm; use crate::worship::Worship; @@ -45,7 +45,7 @@ impl Sermon { pub fn initialize(worship: &Worship) -> Result { - let tmp_dir = &worship.tmp_dir; + let tmp_dir = worship.tmp_dir.as_str(); if let Some(repo) = &worship.repo { println!("Cloning git repo {} into folder {}", repo, tmp_dir); @@ -62,8 +62,17 @@ pub fn initialize(worship: &Worship) -> Result { //TODO: same directory creates recursion if let Ok(_) = fs::read_to_string(sermon_path) { println!("Copying local folder {} into folder {}", worship.source_folder, tmp_dir); - io::create_dir(&tmp_dir, true); - io::copy_all_files_to_dir(&worship.source_folder, tmp_dir); + + let copy_opts: CopyOptions = CopyOptions { + source_dir: &worship.source_folder, + target_dir: tmp_dir, + ensure_target_exists: Some(true), + exclude: Some([tmp_dir].to_vec()), + without_parent_folder: Some(true) + }; + + io::copy_dir(©_opts);//&worship.source_folder, tmp_dir); + } else { println!("Couldn't find sermon {} in local folder: {}", &worship.sermon, &worship.source_folder); return Err("No sermon found".to_string()); diff --git a/src/worship.rs b/src/worship.rs index 85a0937..9a42ae3 100644 --- a/src/worship.rs +++ b/src/worship.rs @@ -19,7 +19,7 @@ pub struct Worship { #[arg(short, long, default_value_t = String::from("./"))] pub target_folder: String, - #[arg(long, default_value_t = String::from("~/.preacher/tmp"))] + #[arg(long, default_value_t = String::from(".preacher/tmp"))] pub tmp_dir: String, }