Browse Source

【初始】创建回收站清理脚本及测试

PJ568 1 năm trước cách đây
commit
694df065f9
7 tập tin đã thay đổi với 906 bổ sung và 0 xóa
  1. 1 0
      .gitignore
  2. 35 0
      CONTRIBUTING.md
  3. 427 0
      LICENSE
  4. 44 0
      README.en.md
  5. 44 0
      README.md
  6. 167 0
      clean_trash.sh
  7. 188 0
      scripts/test_clean_trash.sh

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/target/

+ 35 - 0
CONTRIBUTING.md

@@ -0,0 +1,35 @@
+# 贡献指北
+
+## 项目版本管理
+
+我们使用[语义化版本](https://semver.org/lang/zh-CN/)进行版本管理。
+任何对代码库的更改都不应使用现有版本发布。
+
+## 提交信息格式
+
+提交信息应遵循 [PJ568 提交说明规范](https://github.com/PJ-568/git-commit-regulation)。
+
+## 提交更改
+
+1. Fork 此仓库,在您的仓库新建一个基于此仓库默认分支(branch)的分支。
+2. 在该新建分支对项目进行更改,确保语法不存在问题后应用更改您的仓库。
+3. 向我们的仓库提交拉取请求。请确保您遵循了上述说明。
+4. 我们将定期审查拉取请求,并告知您我们的问题以及在合并您的拉取请求之前需要进行的任何更改。
+5. 我们希望您在 15 日内作出回应,之后如果没有显示活动,您的拉取请求可能会被关闭。
+
+### 参考流程
+
+1. Fork 源码,下载到本地并运行项目;
+2. 添加或修改代码;
+3. 配置 bash 环境并运行 `./scripts/test_clean_trash.sh` 命令以测试脚本功能;
+4. 对相关改动进行更全面的自我测试;
+5. 确认无误后提交修改到 Github;
+6. 提交 Pull Request。
+
+### 注意事项
+
+- 单次 Pull Request 不应提交过多修改,请确保每次提交都针对特定的功能且务必说明本次改动的具体目的,例如:修复某 bug 、优化某方法 等,方便进行 Code Review;
+- 对于 bug 的修复,应该将本次 Pull Request 和相对应 bug 的 issue 关联起来,让别人知道该问题已经被修复;
+- 对于较大的新功能,你需要先提交 Issues,例如 “【新增】添加 XXX 功能”,确认该功能有被添加的必要后,再开始工作;
+- 对于一些主观的样式、交互逻辑调整:如颜色、图标的使用,某些预设配置的增减修改等,一般不予通过。但可以在 Discussions 中进行讨论;
+- 其他如简单的代码优化、文档修正等,只要修改合理都会被接受。

+ 427 - 0
LICENSE

@@ -0,0 +1,427 @@
+Attribution-ShareAlike 4.0 International
+
+=======================================================================
+
+Creative Commons Corporation ("Creative Commons") is not a law firm and
+does not provide legal services or legal advice. Distribution of
+Creative Commons public licenses does not create a lawyer-client or
+other relationship. Creative Commons makes its licenses and related
+information available on an "as-is" basis. Creative Commons gives no
+warranties regarding its licenses, any material licensed under their
+terms and conditions, or any related information. Creative Commons
+disclaims all liability for damages resulting from their use to the
+fullest extent possible.
+
+Using Creative Commons Public Licenses
+
+Creative Commons public licenses provide a standard set of terms and
+conditions that creators and other rights holders may use to share
+original works of authorship and other material subject to copyright
+and certain other rights specified in the public license below. The
+following considerations are for informational purposes only, are not
+exhaustive, and do not form part of our licenses.
+
+     Considerations for licensors: Our public licenses are
+     intended for use by those authorized to give the public
+     permission to use material in ways otherwise restricted by
+     copyright and certain other rights. Our licenses are
+     irrevocable. Licensors should read and understand the terms
+     and conditions of the license they choose before applying it.
+     Licensors should also secure all rights necessary before
+     applying our licenses so that the public can reuse the
+     material as expected. Licensors should clearly mark any
+     material not subject to the license. This includes other CC-
+     licensed material, or material used under an exception or
+     limitation to copyright. More considerations for licensors:
+	wiki.creativecommons.org/Considerations_for_licensors
+
+     Considerations for the public: By using one of our public
+     licenses, a licensor grants the public permission to use the
+     licensed material under specified terms and conditions. If
+     the licensor's permission is not necessary for any reason--for
+     example, because of any applicable exception or limitation to
+     copyright--then that use is not regulated by the license. Our
+     licenses grant only permissions under copyright and certain
+     other rights that a licensor has authority to grant. Use of
+     the licensed material may still be restricted for other
+     reasons, including because others have copyright or other
+     rights in the material. A licensor may make special requests,
+     such as asking that all changes be marked or described.
+     Although not required by our licenses, you are encouraged to
+     respect those requests where reasonable. More_considerations
+     for the public: 
+	wiki.creativecommons.org/Considerations_for_licensees
+
+=======================================================================
+
+Creative Commons Attribution-ShareAlike 4.0 International Public
+License
+
+By exercising the Licensed Rights (defined below), You accept and agree
+to be bound by the terms and conditions of this Creative Commons
+Attribution-ShareAlike 4.0 International Public License ("Public
+License"). To the extent this Public License may be interpreted as a
+contract, You are granted the Licensed Rights in consideration of Your
+acceptance of these terms and conditions, and the Licensor grants You
+such rights in consideration of benefits the Licensor receives from
+making the Licensed Material available under these terms and
+conditions.
+
+
+Section 1 -- Definitions.
+
+  a. Adapted Material means material subject to Copyright and Similar
+     Rights that is derived from or based upon the Licensed Material
+     and in which the Licensed Material is translated, altered,
+     arranged, transformed, or otherwise modified in a manner requiring
+     permission under the Copyright and Similar Rights held by the
+     Licensor. For purposes of this Public License, where the Licensed
+     Material is a musical work, performance, or sound recording,
+     Adapted Material is always produced where the Licensed Material is
+     synched in timed relation with a moving image.
+
+  b. Adapter's License means the license You apply to Your Copyright
+     and Similar Rights in Your contributions to Adapted Material in
+     accordance with the terms and conditions of this Public License.
+
+  c. BY-SA Compatible License means a license listed at
+     creativecommons.org/compatiblelicenses, approved by Creative
+     Commons as essentially the equivalent of this Public License.
+
+  d. Copyright and Similar Rights means copyright and/or similar rights
+     closely related to copyright including, without limitation,
+     performance, broadcast, sound recording, and Sui Generis Database
+     Rights, without regard to how the rights are labeled or
+     categorized. For purposes of this Public License, the rights
+     specified in Section 2(b)(1)-(2) are not Copyright and Similar
+     Rights.
+
+  e. Effective Technological Measures means those measures that, in the
+     absence of proper authority, may not be circumvented under laws
+     fulfilling obligations under Article 11 of the WIPO Copyright
+     Treaty adopted on December 20, 1996, and/or similar international
+     agreements.
+
+  f. Exceptions and Limitations means fair use, fair dealing, and/or
+     any other exception or limitation to Copyright and Similar Rights
+     that applies to Your use of the Licensed Material.
+
+  g. License Elements means the license attributes listed in the name
+     of a Creative Commons Public License. The License Elements of this
+     Public License are Attribution and ShareAlike.
+
+  h. Licensed Material means the artistic or literary work, database,
+     or other material to which the Licensor applied this Public
+     License.
+
+  i. Licensed Rights means the rights granted to You subject to the
+     terms and conditions of this Public License, which are limited to
+     all Copyright and Similar Rights that apply to Your use of the
+     Licensed Material and that the Licensor has authority to license.
+
+  j. Licensor means the individual(s) or entity(ies) granting rights
+     under this Public License.
+
+  k. Share means to provide material to the public by any means or
+     process that requires permission under the Licensed Rights, such
+     as reproduction, public display, public performance, distribution,
+     dissemination, communication, or importation, and to make material
+     available to the public including in ways that members of the
+     public may access the material from a place and at a time
+     individually chosen by them.
+
+  l. Sui Generis Database Rights means rights other than copyright
+     resulting from Directive 96/9/EC of the European Parliament and of
+     the Council of 11 March 1996 on the legal protection of databases,
+     as amended and/or succeeded, as well as other essentially
+     equivalent rights anywhere in the world.
+
+  m. You means the individual or entity exercising the Licensed Rights
+     under this Public License. Your has a corresponding meaning.
+
+
+Section 2 -- Scope.
+
+  a. License grant.
+
+       1. Subject to the terms and conditions of this Public License,
+          the Licensor hereby grants You a worldwide, royalty-free,
+          non-sublicensable, non-exclusive, irrevocable license to
+          exercise the Licensed Rights in the Licensed Material to:
+
+            a. reproduce and Share the Licensed Material, in whole or
+               in part; and
+
+            b. produce, reproduce, and Share Adapted Material.
+
+       2. Exceptions and Limitations. For the avoidance of doubt, where
+          Exceptions and Limitations apply to Your use, this Public
+          License does not apply, and You do not need to comply with
+          its terms and conditions.
+
+       3. Term. The term of this Public License is specified in Section
+          6(a).
+
+       4. Media and formats; technical modifications allowed. The
+          Licensor authorizes You to exercise the Licensed Rights in
+          all media and formats whether now known or hereafter created,
+          and to make technical modifications necessary to do so. The
+          Licensor waives and/or agrees not to assert any right or
+          authority to forbid You from making technical modifications
+          necessary to exercise the Licensed Rights, including
+          technical modifications necessary to circumvent Effective
+          Technological Measures. For purposes of this Public License,
+          simply making modifications authorized by this Section 2(a)
+          (4) never produces Adapted Material.
+
+       5. Downstream recipients.
+
+            a. Offer from the Licensor -- Licensed Material. Every
+               recipient of the Licensed Material automatically
+               receives an offer from the Licensor to exercise the
+               Licensed Rights under the terms and conditions of this
+               Public License.
+
+            b. Additional offer from the Licensor -- Adapted Material.
+               Every recipient of Adapted Material from You
+               automatically receives an offer from the Licensor to
+               exercise the Licensed Rights in the Adapted Material
+               under the conditions of the Adapter's License You apply.
+
+            c. No downstream restrictions. You may not offer or impose
+               any additional or different terms or conditions on, or
+               apply any Effective Technological Measures to, the
+               Licensed Material if doing so restricts exercise of the
+               Licensed Rights by any recipient of the Licensed
+               Material.
+
+       6. No endorsement. Nothing in this Public License constitutes or
+          may be construed as permission to assert or imply that You
+          are, or that Your use of the Licensed Material is, connected
+          with, or sponsored, endorsed, or granted official status by,
+          the Licensor or others designated to receive attribution as
+          provided in Section 3(a)(1)(A)(i).
+
+  b. Other rights.
+
+       1. Moral rights, such as the right of integrity, are not
+          licensed under this Public License, nor are publicity,
+          privacy, and/or other similar personality rights; however, to
+          the extent possible, the Licensor waives and/or agrees not to
+          assert any such rights held by the Licensor to the limited
+          extent necessary to allow You to exercise the Licensed
+          Rights, but not otherwise.
+
+       2. Patent and trademark rights are not licensed under this
+          Public License.
+
+       3. To the extent possible, the Licensor waives any right to
+          collect royalties from You for the exercise of the Licensed
+          Rights, whether directly or through a collecting society
+          under any voluntary or waivable statutory or compulsory
+          licensing scheme. In all other cases the Licensor expressly
+          reserves any right to collect such royalties.
+
+
+Section 3 -- License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the
+following conditions.
+
+  a. Attribution.
+
+       1. If You Share the Licensed Material (including in modified
+          form), You must:
+
+            a. retain the following if it is supplied by the Licensor
+               with the Licensed Material:
+
+                 i. identification of the creator(s) of the Licensed
+                    Material and any others designated to receive
+                    attribution, in any reasonable manner requested by
+                    the Licensor (including by pseudonym if
+                    designated);
+
+                ii. a copyright notice;
+
+               iii. a notice that refers to this Public License;
+
+                iv. a notice that refers to the disclaimer of
+                    warranties;
+
+                 v. a URI or hyperlink to the Licensed Material to the
+                    extent reasonably practicable;
+
+            b. indicate if You modified the Licensed Material and
+               retain an indication of any previous modifications; and
+
+            c. indicate the Licensed Material is licensed under this
+               Public License, and include the text of, or the URI or
+               hyperlink to, this Public License.
+
+       2. You may satisfy the conditions in Section 3(a)(1) in any
+          reasonable manner based on the medium, means, and context in
+          which You Share the Licensed Material. For example, it may be
+          reasonable to satisfy the conditions by providing a URI or
+          hyperlink to a resource that includes the required
+          information.
+
+       3. If requested by the Licensor, You must remove any of the
+          information required by Section 3(a)(1)(A) to the extent
+          reasonably practicable.
+
+  b. ShareAlike.
+
+     In addition to the conditions in Section 3(a), if You Share
+     Adapted Material You produce, the following conditions also apply.
+
+       1. The Adapter's License You apply must be a Creative Commons
+          license with the same License Elements, this version or
+          later, or a BY-SA Compatible License.
+
+       2. You must include the text of, or the URI or hyperlink to, the
+          Adapter's License You apply. You may satisfy this condition
+          in any reasonable manner based on the medium, means, and
+          context in which You Share Adapted Material.
+
+       3. You may not offer or impose any additional or different terms
+          or conditions on, or apply any Effective Technological
+          Measures to, Adapted Material that restrict exercise of the
+          rights granted under the Adapter's License You apply.
+
+
+Section 4 -- Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that
+apply to Your use of the Licensed Material:
+
+  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+     to extract, reuse, reproduce, and Share all or a substantial
+     portion of the contents of the database;
+
+  b. if You include all or a substantial portion of the database
+     contents in a database in which You have Sui Generis Database
+     Rights, then the database in which You have Sui Generis Database
+     Rights (but not its individual contents) is Adapted Material,
+
+     including for purposes of Section 3(b); and
+  c. You must comply with the conditions in Section 3(a) if You Share
+     all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not
+replace Your obligations under this Public License where the Licensed
+Rights include other Copyright and Similar Rights.
+
+
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+
+  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
+
+  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
+     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
+
+  c. The disclaimer of warranties and limitation of liability provided
+     above shall be interpreted in a manner that, to the extent
+     possible, most closely approximates an absolute disclaimer and
+     waiver of all liability.
+
+
+Section 6 -- Term and Termination.
+
+  a. This Public License applies for the term of the Copyright and
+     Similar Rights licensed here. However, if You fail to comply with
+     this Public License, then Your rights under this Public License
+     terminate automatically.
+
+  b. Where Your right to use the Licensed Material has terminated under
+     Section 6(a), it reinstates:
+
+       1. automatically as of the date the violation is cured, provided
+          it is cured within 30 days of Your discovery of the
+          violation; or
+
+       2. upon express reinstatement by the Licensor.
+
+     For the avoidance of doubt, this Section 6(b) does not affect any
+     right the Licensor may have to seek remedies for Your violations
+     of this Public License.
+
+  c. For the avoidance of doubt, the Licensor may also offer the
+     Licensed Material under separate terms or conditions or stop
+     distributing the Licensed Material at any time; however, doing so
+     will not terminate this Public License.
+
+  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+     License.
+
+
+Section 7 -- Other Terms and Conditions.
+
+  a. The Licensor shall not be bound by any additional or different
+     terms or conditions communicated by You unless expressly agreed.
+
+  b. Any arrangements, understandings, or agreements regarding the
+     Licensed Material not stated herein are separate from and
+     independent of the terms and conditions of this Public License.
+
+
+Section 8 -- Interpretation.
+
+  a. For the avoidance of doubt, this Public License does not, and
+     shall not be interpreted to, reduce, limit, restrict, or impose
+     conditions on any use of the Licensed Material that could lawfully
+     be made without permission under this Public License.
+
+  b. To the extent possible, if any provision of this Public License is
+     deemed unenforceable, it shall be automatically reformed to the
+     minimum extent necessary to make it enforceable. If the provision
+     cannot be reformed, it shall be severed from this Public License
+     without affecting the enforceability of the remaining terms and
+     conditions.
+
+  c. No term or condition of this Public License will be waived and no
+     failure to comply consented to unless expressly agreed to by the
+     Licensor.
+
+  d. Nothing in this Public License constitutes or may be interpreted
+     as a limitation upon, or waiver of, any privileges and immunities
+     that apply to the Licensor or You, including from the legal
+     processes of any jurisdiction or authority.
+
+
+=======================================================================
+
+Creative Commons is not a party to its public
+licenses. Notwithstanding, Creative Commons may elect to apply one of
+its public licenses to material it publishes and in those instances
+will be considered the “Licensor.” The text of the Creative Commons
+public licenses is dedicated to the public domain under the CC0 Public
+Domain Dedication. Except for the limited purpose of indicating that
+material is shared under a Creative Commons public license or as
+otherwise permitted by the Creative Commons policies published at
+creativecommons.org/policies, Creative Commons does not authorize the
+use of the trademark "Creative Commons" or any other trademark or logo
+of Creative Commons without its prior written consent including,
+without limitation, in connection with any unauthorized modifications
+to any of its public licenses or any other arrangements,
+understandings, or agreements concerning use of licensed material. For
+the avoidance of doubt, this paragraph does not form part of the
+public licenses.
+
+Creative Commons may be contacted at creativecommons.org.

+ 44 - 0
README.en.md

@@ -0,0 +1,44 @@
+# Trash Cleaner Script
+
+[![License: CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-sa/4.0/)
+
+> [简体中文](README.md) | English
+
+A script to clean files in the trash that have been kept for more than a specified number of days.
+
+```bash
+Trash Cleaner Tool
+Usage: ./clean_trash.sh [-h] [-v] <days to keep>
+Options:
+  -h  Show help message
+  -v  Verbose output mode
+Examples:
+  ./clean_trash.sh 30    # Clean trash files older than 30 days
+  ./clean_trash.sh -v 7  # Verbose mode to clean files older than 7 days
+```
+
+## Contributing
+
+[Contribution Guide](CONTRIBUTING.md)
+
+## Overview of Linux Trash Mechanism
+
+When you "delete" a file in a Linux desktop environment, it moves the file to a special "trash" directory, which is usually `~/.local/share/Trash/`.
+The trash directory typically contains three subdirectories:
+
+- `files/`: Stores the deleted **files** themselves. For example: `question.png`.
+- `info/`: Stores **metadata** related to the deleted files (such as the original path, deletion timestamp, etc.). For example:
+
+  ```plaintext ~/.local/share/Trash/info/question.png.trashinfo
+  [Trash Info]
+  Path=/home/user/question.png
+  DeletionDate=2025-08-13T19:47:35
+  ```
+
+- `expunged/`: Temporarily stores files that are to be **permanently deleted**.
+
+### Purpose of the `expunged` Folder
+
+- **"Permanent Deletion" Operation:** When you decide to empty the trash (select the "Empty Trash" menu item in the file manager), the desktop environment does not simply delete all the contents of the `files/` and `info/` directories.
+- **Marking Process:** It first **moves** the corresponding files in the `files/` directory to the `~/.local/share/Trash/expunged/` directory (because moving files is fast).
+- **Physical Deletion:** Then, it **physically deletes** the corresponding metadata files in the `info/` directory; and slowly **physically deletes** the corresponding files in the `expunged/` directory (deleting a large number of files takes time, and doing it too quickly may slow down the entire computer).

+ 44 - 0
README.md

@@ -0,0 +1,44 @@
+# 垃圾清理脚本
+
+[![License: CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-sa/4.0/)
+
+> 简体中文 | [English](README.en.md)
+
+实现清理在回收站里保存超过指定天数的文件。
+
+```bash
+回收站清理工具
+用法:./clean_trash.sh [-h] [-v] <保留天数>
+选项:
+  -h  显示帮助信息
+  -v  详细输出模式
+示例:
+  ./clean_trash.sh 30    # 清理 30 天前的回收站文件
+  ./clean_trash.sh -v 7  # 详细模式清理 7 天前文件
+```
+
+## 贡献
+
+[贡献指北](CONTRIBUTING.md)
+
+## Linux 回收站机制概述
+
+Linux 桌面环境“删除”一个文件时会将它移动到一个特殊的“回收站”目录中,这个目录通常是 `~/.local/share/Trash/`。
+回收站目录内部通常有三个子目录:
+
+- `files/`: 存放被删除的**文件**本身。如:`提问.png`。
+- `info/`: 存放与被删除文件相关的**元数据**(如原始路径、删除时间戳等)。如:
+
+  ```plaintext ~/.local/share/Trash/info/提问.png.trashinfo
+  [Trash Info]
+  Path=/home/user/%E6%8F%90%E9%97%AE.png
+  DeletionDate=2025-08-13T19:47:35
+  ```
+
+- `expunged/`: 临时存放要**被永久删除**的文件。
+
+### `expunged` 文件夹的作用
+
+- **“永久删除”操作:** 当你决定清空回收站(在文件管理器中选择“清空回收站”菜单项)时,桌面环境并不会简单地删除 `files/` 和 `info/` 目录里的所有内容。
+- **标记过程:** 它首先会将 `files/` 目录中对应的文件**移动**到 `~/.local/share/Trash/expunged/` 目录中(因为移动文件很快)。
+- **物理删除:** 然后,它会**物理删除** `info/` 目录中对应的元数据文件;慢慢**物理删除** `expunged/` 目录中对应的文件(删除大量文件需要时间,过快地进行可能会减慢整个计算机的速度)。

+ 167 - 0
clean_trash.sh

@@ -0,0 +1,167 @@
+#!/usr/bin/env bash
+
+# 设置定量 | Quantities
+## 初始化变量 | Initialize variables
+VERBOSE=0
+## 当前语言 | Current language
+CURRENT_LANG=0 # 0: en-US, 1: zh-Hans-CN
+## 定义回收站目录 | Define trash directory
+TRASH_DIR="${TRASH_DIR:-$HOME/.local/share/Trash}"
+FILES_DIR="${FILES_DIR:-$TRASH_DIR/files}"
+INFO_DIR="${INFO_DIR:-$TRASH_DIR/info}"
+EXPUNGED_DIR="${EXPUNGED_DIR:-$TRASH_DIR/expunged}"
+
+# 本地化 | Localization
+recho() {
+  if [ $CURRENT_LANG == 1 ]; then
+    ## zh-Hans-CN
+    echo "$1";
+  else
+    ## en-US
+    echo "$2";
+  fi
+}
+
+# 显示帮助信息 | Show help message
+show_help() {
+  recho "回收站清理工具" "Trash cleaner tool"
+  recho "用法:$0 [-h] [-v] <保留天数>" "Usage: $0 [-h] [-v] <days>"
+  recho "选项:" "Options:"
+  recho "  -h  显示帮助信息" "  -h  Show help"
+  recho "  -v  详细输出模式" "  -v  Verbose mode"
+  recho "示例:" "Examples:"
+  recho "  $0 30    # 清理 30 天前的回收站文件" "  $0 30    # Clean trash files older than 30 days"
+  recho "  $0 -v 7  # 详细模式清理 7 天前文件" "  $0 -v 7  # Verbose mode to clean files older than 7 days"
+}
+
+# 语言检测 | Language detection
+if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1; fi
+
+# 解析选项 | Parse options
+while getopts ":hv" opt; do
+  case $opt in
+    h) show_help ; exit 0 ;;
+    v) VERBOSE=1 ;;
+    \?) recho "错误:无效选项 -$OPTARG" "Error: Invalid option -$OPTARG" >&2; exit 1 ;;
+  esac
+done
+shift $((OPTIND-1))
+
+# 检查是否提供了天数参数 | Check if days parameter was provided
+if [ $# -ne 1 ]; then
+  recho "错误:需要提供保留天数参数" "Error: Need to provide days parameter" >&2
+  show_help
+  exit 1
+fi
+
+# 获取天数参数 | Get days parameter
+DAYS=$1
+
+# 检查天数是否为正整数 | Check if days is a positive integer
+if ! [[ "$DAYS" =~ ^[0-9]+$ ]] || [ "$DAYS" -le 0 ]; then
+  recho "错误:天数必须是正整数" "Error: Days must be a positive integer" >&2
+  exit 1
+fi
+
+# 检查回收站目录结构 | Check trash directory structure
+if [ ! -d "$FILES_DIR" ] || [ ! -d "$INFO_DIR" ]; then
+  recho "错误:回收站目录结构不正确" "Error: Trash directory structure is incorrect" >&2
+  recho "请确认目录存在:$FILES_DIR 和 $INFO_DIR" "Please confirm directories exist: $FILES_DIR and $INFO_DIR" >&2
+  exit 1
+fi
+
+# 获取当前时间戳 | Get current timestamp
+CURRENT_TIME=$(date +%s)
+
+# 计算截止时间戳 | Calculate cutoff timestamp
+CUTOFF_TIME=$((CURRENT_TIME - DAYS * 24 * 60 * 60))
+
+# 初始化计数器 | Initialize counters
+DELETED_COUNT=0
+ERROR_COUNT=0
+
+# 确保 expunged 目录存在 | Ensure expunged directory exists
+mkdir -p "$EXPUNGED_DIR"
+
+# 遍历 info 目录中的所有 .trashinfo 文件 | Iterate through all .trashinfo files in info directory
+for INFO_FILE in "$INFO_DIR"/*.trashinfo; do
+  # 检查文件是否存在 | Check if file exists
+  if [ ! -f "$INFO_FILE" ]; then
+    continue
+  fi
+  
+  # 获取对应的文件名 | Get corresponding filename
+  BASENAME=$(basename "$INFO_FILE" .trashinfo)
+  TRASH_FILE="$FILES_DIR/$BASENAME"
+  
+  # 检查对应的文件是否存在 | Check if corresponding file exists
+  if [ ! -e "$TRASH_FILE" ]; then
+    if [ $VERBOSE -eq 1 ]; then
+      recho "警告:找不到对应文件 $TRASH_FILE" "Warning: Cannot find corresponding file $TRASH_FILE" >&2
+    fi
+    continue
+  fi
+  
+  # 从 .trashinfo 文件中提取 DeletionDate | Extract DeletionDate from .trashinfo file
+  DELETION_DATE=$(grep -E "^DeletionDate=" "$INFO_FILE" | cut -d'=' -f2)
+  
+  # 检查是否成功提取日期 | Check if date was extracted successfully
+  if [ -z "$DELETION_DATE" ]; then
+    if [ $VERBOSE -eq 1 ]; then
+      recho "警告:无法从 $INFO_FILE 提取删除日期" "Warning: Cannot extract deletion date from $INFO_FILE" >&2
+    fi
+    continue
+  fi
+  
+  # 将删除日期转换为时间戳 | Convert deletion date to timestamp
+  # 注意:日期格式为 2025-08-13T19:47:35
+  DELETION_TIMESTAMP=$(date -d "$DELETION_DATE" +%s 2>/dev/null)
+  
+  # 检查日期转换是否成功 | Check if date conversion was successful
+  if [ $? -ne 0 ] || [ -z "$DELETION_TIMESTAMP" ]; then
+    if [ $VERBOSE -eq 1 ]; then
+      recho "警告:无法解析删除日期 $DELETION_DATE" "Warning: Cannot parse deletion date $DELETION_DATE" >&2
+    fi
+    continue
+  fi
+  
+  # 检查文件是否超过保留天数 | Check if file exceeds retention days
+  if [ "$DELETION_TIMESTAMP" -lt "$CUTOFF_TIME" ]; then
+    # 创建唯一的 expunged 文件名 | Create unique expunged filename
+    EXPUNGED_FILE="$EXPUNGED_DIR/$BASENAME"
+    
+    # 如果文件已存在,则添加时间戳以确保唯一性 | If file exists, add timestamp to ensure uniqueness
+    if [ -e "$EXPUNGED_FILE" ]; then
+      EXPUNGED_FILE="$EXPUNGED_DIR/${BASENAME}_$(date +%s)"
+    fi
+    
+    # 将文件移动到 expunged 目录 | Move file to expunged directory
+    if [ $VERBOSE -eq 1 ]; then
+      recho "移动文件到 expunged: $TRASH_FILE (删除于 $DELETION_DATE)" "Moving file to expunged: $TRASH_FILE (deleted at $DELETION_DATE)"
+    fi
+    
+    if mv "$TRASH_FILE" "$EXPUNGED_FILE"; then
+      # 删除元数据文件 | Delete metadata file
+      rm -f "$INFO_FILE"
+      DELETED_COUNT=$((DELETED_COUNT + 1))
+    else
+      ERROR_COUNT=$((ERROR_COUNT + 1))
+      recho "错误:无法移动文件到 expunged 目录" "Error: Cannot move file to expunged directory" >&2
+    fi
+  fi
+done
+
+# 物理删除 expunged 目录中的所有文件 | Physically delete all files in expunged directory
+if [ -d "$EXPUNGED_DIR" ]; then
+  if [ $VERBOSE -eq 1 ]; then
+    EXPUNGED_COUNT=$(find "$EXPUNGED_DIR" -mindepth 1 2>/dev/null | wc -l)
+    if [ "$EXPUNGED_COUNT" -gt 0 ]; then
+      recho "物理删除 expunged 目录中的 $EXPUNGED_COUNT 个文件" "Physically deleting $EXPUNGED_COUNT files in expunged directory"
+    fi
+  fi
+  # 物理删除 expunged 目录中的所有内容 | Physically delete all contents in expunged directory
+  rm -rf "$EXPUNGED_DIR"/* 2>/dev/null
+fi
+
+# 输出结果 | Output results
+recho "清理完成:删除了 $DELETED_COUNT 个文件,$ERROR_COUNT 个错误" "Cleanup completed: $DELETED_COUNT files deleted, $ERROR_COUNT errors"

+ 188 - 0
scripts/test_clean_trash.sh

@@ -0,0 +1,188 @@
+#!/usr/bin/env bash
+
+# 设置定量 | Quantities
+## 仓库目录 | Repository directory
+REPO_DIR="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)"
+TEST_DIR="$REPO_DIR/target/test"
+
+# 清理之前的测试环境 | Clean up previous test environment
+rm -rf "$TEST_DIR"
+mkdir -p "$TEST_DIR"
+
+# 测试函数 | Test functions
+test_cleanup() {
+  echo "=== 测试清理功能 ==="
+  
+  # 创建测试回收站目录 | Create test trash directories
+  TRASH_DIR="$TEST_DIR/trash"
+  FILES_DIR="$TRASH_DIR/files"
+  INFO_DIR="$TRASH_DIR/info"
+  EXPUNGED_DIR="$TRASH_DIR/expunged"
+  
+  mkdir -p "$FILES_DIR" "$INFO_DIR" "$EXPUNGED_DIR"
+  
+  # 计算测试日期 | Calculate test dates
+  # 旧文件应该被删除 (10天前) | Old file should be deleted (10 days ago)
+  OLD_DATE=$(date -d "10 days ago" -Iseconds)
+  # 新文件应该保留 (1小时前) | New file should be kept (1 hour ago)
+  NEW_DATE=$(date -d "1 hour ago" -Iseconds)
+  
+  # 创建测试文件 | Create test files
+  # 1. 创建一个旧文件(应该被删除)| Create an old file (should be deleted)
+  echo "This is an old file" > "$FILES_DIR/old_file.txt"
+  cat > "$INFO_DIR/old_file.txt.trashinfo" <<EOF
+[Trash Info]
+Path=/test/old_file.txt
+DeletionDate=$OLD_DATE
+EOF
+  
+  # 2. 创建一个新文件(应该保留)| Create a new file (should be kept)
+  echo "This is a new file" > "$FILES_DIR/new_file.txt"
+  cat > "$INFO_DIR/new_file.txt.trashinfo" <<EOF
+[Trash Info]
+Path=/test/new_file.txt
+DeletionDate=$NEW_DATE
+EOF
+  
+  # 3. 创建一个没有对应文件的元数据(应该报告警告)| Create metadata without corresponding file
+  cat > "$INFO_DIR/orphaned.trashinfo" <<EOF
+[Trash Info]
+Path=/test/orphaned.txt
+DeletionDate=$OLD_DATE
+EOF
+  
+  # 4. 创建一个没有元数据的文件(应该报告警告)| Create file without metadata
+  echo "This file has no metadata" > "$FILES_DIR/no_metadata.txt"
+  
+  # 设置环境变量 | Set environment variables
+  export TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+  
+  # 运行清理脚本 | Run cleanup script
+  echo "运行清理脚本 (保留7天)..."
+  "$REPO_DIR/clean_trash.sh" -v 7
+  
+  # 验证结果 | Verify results
+  echo "验证结果..."
+  if [ ! -f "$FILES_DIR/old_file.txt" ] && [ ! -f "$INFO_DIR/old_file.txt.trashinfo" ]; then
+    echo "✓ 旧文件已正确删除"
+  else
+    echo "✗ 旧文件未被删除"
+  fi
+  
+  if [ -f "$FILES_DIR/new_file.txt" ] && [ -f "$INFO_DIR/new_file.txt.trashinfo" ]; then
+    echo "✓ 新文件已正确保留"
+  else
+    echo "✗ 新文件被错误删除"
+  fi
+  
+  if [ -f "$INFO_DIR/orphaned.trashinfo" ]; then
+    echo "✓ 孤立元数据已保留"
+  else
+    echo "✗ 孤立元数据被错误删除"
+  fi
+  
+  # 清理环境变量 | Clean up environment variables
+  unset TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+}
+
+test_help() {
+  echo "=== 测试帮助信息 ==="
+  "$REPO_DIR/clean_trash.sh" -h
+  # 帮助命令应该成功执行并返回0 | Help command should execute successfully and return 0
+  if [ $? -eq 0 ]; then
+    echo "✓ 帮助信息显示正常"
+  else
+    echo "✗ 帮助信息显示异常"
+  fi
+}
+
+test_invalid_args() {
+  echo "=== 测试无效参数 ==="
+  
+  echo "测试缺少参数..."
+  OUTPUT=$( "$REPO_DIR/clean_trash.sh" 2>&1 )
+  EXIT_CODE=$?
+  # 检查是否显示了错误信息和帮助信息 | Check if error message and help message are displayed
+  if echo "$OUTPUT" | grep -q "错误:需要提供保留天数参数\|Error: Need to provide days parameter" && 
+     echo "$OUTPUT" | grep -q "回收站清理工具\|Trash cleaner tool"; then
+    echo "✓ 缺少参数时正确显示错误信息和帮助信息"
+  else
+    echo "✗ 缺少参数时未正确显示错误信息和帮助信息"
+  fi
+  
+  echo "测试非数字参数..."
+  "$REPO_DIR/clean_trash.sh" abc 2>/dev/null
+  if [ $? -ne 0 ]; then
+    echo "✓ 正确拒绝非数字参数"
+  else
+    echo "✗ 应该失败"
+  fi
+  
+  echo "测试负数参数..."
+  "$REPO_DIR/clean_trash.sh" -1 2>/dev/null
+  if [ $? -ne 0 ]; then
+    echo "✓ 正确拒绝负数参数"
+  else
+    echo "✗ 应该失败"
+  fi
+  
+  echo "测试零值参数..."
+  "$REPO_DIR/clean_trash.sh" 0 2>/dev/null
+  if [ $? -ne 0 ]; then
+    echo "✓ 正确拒绝零值参数"
+  else
+    echo "✗ 应该失败"
+  fi
+}
+
+test_directory_structure() {
+  echo "=== 测试目录结构检查 ==="
+  
+  TRASH_DIR="$TEST_DIR/trash_incomplete"
+  FILES_DIR="$TRASH_DIR/files"
+  INFO_DIR="$TRASH_DIR/info"
+  EXPUNGED_DIR="$TRASH_DIR/expunged"
+  
+  # 只创建部分目录 | Create only partial directories
+  mkdir -p "$TRASH_DIR"
+  mkdir -p "$FILES_DIR"
+  # 故意不创建 info 目录 | Intentionally not creating info directory
+  
+  export TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+  
+  "$REPO_DIR/clean_trash.sh" 7 && echo "✗ 应该失败" || echo "✓ 正确拒绝不完整的目录结构"
+  
+  unset TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+}
+
+# 运行所有测试 | Run all tests
+echo "开始测试..."
+test_help
+test_invalid_args
+test_directory_structure
+test_cleanup
+
+# 测试详细模式
+echo "=== 测试详细模式 ==="
+# 使用之前的测试环境
+TRASH_DIR="$TEST_DIR/trash"
+FILES_DIR="$TRASH_DIR/files"
+INFO_DIR="$TRASH_DIR/info"
+EXPUNGED_DIR="$TRASH_DIR/expunged"
+
+# 添加另一个旧文件用于测试
+echo "This is another old file" > "$FILES_DIR/old_file2.txt"
+cat > "$INFO_DIR/old_file2.txt.trashinfo" <<EOF
+[Trash Info]
+Path=/test/old_file2.txt
+DeletionDate=$(date -d "10 days ago" -Iseconds)
+EOF
+
+export TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+
+echo "运行详细模式清理..."
+"$REPO_DIR/clean_trash.sh" -v 7
+
+unset TRASH_DIR FILES_DIR INFO_DIR EXPUNGED_DIR
+
+echo "测试完成。"