Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`PathBuf` lets us check to see if a file exists before writing to it, so we can take advantage of that to make sure that we don't overwrite a file that already exists, even if the user has indicated a title that would overwrite another file. ``` let mut i: usize = 0; loop { let dest_filename = format!( "{}{}", filename, if i == 0 { "".to_string() } else { i.to_string() } ); let mut dest = garden_path.join(dest_filename); dest.set_extension("md"); if dest.exists() { i = i + 1; } else { fs::rename(garden_tmpfile, &dest)?; break; } } ```
- Loading branch information
1 parent
7d45753
commit 97a861d
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters