File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed
Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -145,15 +145,19 @@ impl Dot {
145145 // Single file : inject vars and write to .dots/
146146 if source. is_file ( ) {
147147 fs:: create_dir_all ( & target. parent ( ) . unwrap ( ) ) ?;
148- if let Ok ( content) = vars. to_dot ( source) {
149- let permissions = fs:: metadata ( source) ?. permissions ( ) ;
150- let mut dot_copy = File :: create ( & target) ?;
151- dot_copy. write_all ( content. as_bytes ( ) ) ?;
152- dot_copy. set_permissions ( permissions) ?;
153- } else {
154- // Something went wrong parsing or reading the source path,
155- // We just copy the file in place
156- fs:: copy ( source, target) ?;
148+ match vars. to_dot ( source) {
149+ Ok ( content) => {
150+ let permissions = fs:: metadata ( source) ?. permissions ( ) ;
151+ let mut dot_copy = File :: create ( & target) ?;
152+ dot_copy. write_all ( content. as_bytes ( ) ) ?;
153+ dot_copy. set_permissions ( permissions) ?;
154+ }
155+ Err ( err) => {
156+ // Something went wrong parsing or reading the source path,
157+ // We just copy the file in place
158+ fs:: copy ( source, target) ?;
159+ eprintln ! ( "{err:?}" )
160+ }
157161 }
158162 } else if source. is_dir ( ) {
159163 fs:: create_dir_all ( target) ?;
Original file line number Diff line number Diff line change 11use crate :: gpg:: { Gpg , GPG_PREFIX } ;
2- use anyhow:: { anyhow, Context , Result } ;
2+ use anyhow:: { anyhow, Result } ;
33use colored:: Colorize ;
44use std:: collections:: HashMap ;
55use std:: fs:: File ;
66use std:: io:: prelude:: * ;
77use std:: io:: BufReader ;
88use std:: path:: { Path , PathBuf } ;
9+ use tera:: Tera ;
910
1011#[ derive( Clone , Debug , Default ) ]
1112pub ( crate ) struct Variables {
@@ -82,8 +83,11 @@ impl Variables {
8283 context. insert ( k. to_owned ( ) , v) ;
8384 } ) ;
8485
85- tera:: Tera :: one_off ( & contents, & context, false )
86- . context ( "Failed to apply templating to file:" )
86+ let mut tera = Tera :: default ( ) ;
87+ let filename = path. as_os_str ( ) . to_str ( ) . expect ( "Non UTF8 filename" ) ;
88+
89+ tera. add_raw_template ( filename, & contents) ?;
90+ tera. render ( filename, & context) . map_err ( Into :: into)
8791 }
8892
8993 pub ( crate ) fn resolve_ref ( & mut self ) {
You can’t perform that action at this time.
0 commit comments