diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-04-04 20:25:23 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-04-04 20:26:59 +0300 |
commit | 1886a9b3ff464d43f296603d8a95126f0c1a2a5a (patch) | |
tree | f28c49d6c1883f172ac96be5001fdd2c94397aa9 /src | |
parent | 7894a7f712e67dd850ef34bfe9f7ade02f52f832 (diff) | |
download | cachedir-rs-1886a9b3ff464d43f296603d8a95126f0c1a2a5a.tar.gz |
feat: put re-usable parts into crate library
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/cachedir.rs | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/src/bin/cachedir.rs b/src/bin/cachedir.rs index 4d35ae8..0675248 100644 --- a/src/bin/cachedir.rs +++ b/src/bin/cachedir.rs @@ -12,17 +12,12 @@ //! $ //! ~~~ +use cachedir::{is_cachedir_tag, CACHEDIR_TAG, TAG}; use clap::{Parser, Subcommand}; -use std::fs::{read, remove_file, write}; -use std::path::{Path, PathBuf}; +use std::fs::{remove_file, write}; +use std::path::PathBuf; use walkdir::{DirEntry, WalkDir}; -/// Name of tag file. -const CACHEDIR_TAG: &str = "CACHEDIR.TAG"; - -/// Prefix of contents of tag file. -const TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55"; - /// The main program. fn main() { if let Err(e) = real_main() { @@ -115,20 +110,6 @@ where Ok(()) } -/// Is the given file a cache directory tag? -fn is_cachedir_tag(filename: &Path) -> Result<bool, std::io::Error> { - if filename.exists() { - let data = read(filename)?; - if data.len() >= TAG.len() { - Ok(&data[..TAG.len()] == TAG.as_bytes()) - } else { - Ok(false) - } - } else { - Ok(false) - } -} - /// Return path to tag file in a directory. fn tag_filename(entry: &DirEntry) -> PathBuf { entry.path().join(CACHEDIR_TAG) |