From 1886a9b3ff464d43f296603d8a95126f0c1a2a5a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 4 Apr 2022 20:25:23 +0300 Subject: feat: put re-usable parts into crate library Sponsored-by: author --- src/bin/cachedir.rs | 25 +++---------------------- 1 file 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 { - 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) -- cgit v1.2.1