T09 · Insecure Skill Coding Practices
- Location
scripts/archive_books.py:151- Finding
Unfiltered Documents Can Be Copied into a Cloud-Synchronized Directory
- Content
View full analysis
str: """根据文件名关键词,判断书籍应归档到哪个分类""" name_lower = filename.lower() for keywords, category in CLASSIFICATION_RULES: for kw in keywords: if kw.lower() in name_lower: return category return '10_参考资料' # 默认归入参考资料 def get_archive_destinations(filename: str) -> tuple: """获取归档目标路径(本地 + 百度盘)""" category = classify_book(filename) return KB / category, (BD / category) if BD.exists() else None def archive_file(src_path: Path, dry_run: bool = False) -> dict: """归档单个文件,返回结果信息""" local_dest, bd_dest = get_archive_destinations(src_path.name) local_dest.mkdir(parents=True, exist_ok=True) dest_path = local_dest / src_path.name if dest_path.exists(): return {'status': 'exists', 'dest': str(dest_path), 'name': src_path.name} if dry_run: return {'status': 'would_copy', 'dest': str(dest_path), 'name': src_path.name} shutil.copy2(src_path, dest_path) # 同时复制到百度盘 if bd_dest: bd_dest.mkdir(parents=True, exist_ok=True) shutil.copy2(src_path, bd_dest / src_path.name) return {'status': 'archived', 'dest': str(dest_path), 'name': src_path.name} ``` ```python EXTENSIONS = {'.pdf', '.epub', '.mobi', '.azw3', '.djvu', '.cbz', '.cbr'} candidates = [ f for f in DOWNLOADS.iterdir() if f.is_file() and f.suffix.lower() in EXTENSIONS ] if not candidates: print("下载目录中没有找到书籍文件。") return print(f"📋 找到 {len(candidates)} 个候选文件,开始归档……") print() results = {'archived': [], 'skipped': [], 'errors': []} for f in candidates: try: result = archive_file(f) ``` ### Technical Analysis The archival script processes every top-level file in the configured Downloads directory whose ...[truncated 2390 chars]- Remediation
View remediation
