File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use std::fs;
88use std:: fs:: File ;
99use std:: io:: Write ;
1010use std:: path:: Path ;
11+ use std:: time:: SystemTime ;
1112
1213#[ derive( Deserialize , Debug ) ]
1314struct Bite {
@@ -57,6 +58,17 @@ fn write_exercise(path: &Path, template: String) -> std::io::Result<()> {
5758 let src_dir = path. join ( "src" ) ;
5859 fs:: create_dir_all ( & src_dir) ?;
5960 let filename = src_dir. join ( "lib.rs" ) ;
61+
62+ if fs:: exists ( & filename) ? {
63+ // backup the original lib.rs (exercise file) by adding a UNIX_EPOCH timestamp after .rs
64+ let now = SystemTime :: now ( )
65+ . duration_since ( SystemTime :: UNIX_EPOCH )
66+ . unwrap ( )
67+ . as_secs ( ) ;
68+ let new_filename = & filename. with_extension ( format ! ( "rs.{}" , now) ) ;
69+ fs:: rename ( & filename, new_filename) ?;
70+ }
71+
6072 let mut file = File :: create ( filename) ?;
6173 file. write_all ( template. as_bytes ( ) ) ?;
6274 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments