mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-12-18 14:49:07 +08:00
set default safeguards against mass deletion in remove orphan
This commit is contained in:
parent
c2667f73b6
commit
aa82ba8db3
6 changed files with 30 additions and 14 deletions
|
|
@ -61,11 +61,3 @@ repos:
|
||||||
language: script
|
language: script
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
stages: [commit]
|
stages: [commit]
|
||||||
- repo: local
|
|
||||||
hooks:
|
|
||||||
- id: update-readme-version
|
|
||||||
name: Update readme version
|
|
||||||
entry: ./scripts/pre-commit/update-readme-version.sh
|
|
||||||
language: script
|
|
||||||
pass_filenames: false
|
|
||||||
stages: [commit]
|
|
||||||
|
|
|
||||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
4.1.11-develop4
|
4.1.11-develop5
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,10 @@ orphaned:
|
||||||
- "/data/torrents/temp/**"
|
- "/data/torrents/temp/**"
|
||||||
- "**/*.!qB"
|
- "**/*.!qB"
|
||||||
- "**/*_unpackerred"
|
- "**/*_unpackerred"
|
||||||
|
# Set your desired threshold for the maximum number of orphaned files qbm will delete in a single run. (-1 to disable safeguards)
|
||||||
|
# This will help reduce the number of accidental large amount orphaned deletions in a single run
|
||||||
|
# WARNING: Setting this variable to -1 will not safeguard against any deletions
|
||||||
|
max_orphaned_files_to_delete: 50
|
||||||
|
|
||||||
apprise:
|
apprise:
|
||||||
# Apprise integration with webhooks
|
# Apprise integration with webhooks
|
||||||
|
|
|
||||||
|
|
@ -726,6 +726,14 @@ class Config:
|
||||||
self.orphaned["exclude_patterns"] = self.util.check_for_attribute(
|
self.orphaned["exclude_patterns"] = self.util.check_for_attribute(
|
||||||
self.data, "exclude_patterns", parent="orphaned", var_type="list", default_is_none=True, do_print=False
|
self.data, "exclude_patterns", parent="orphaned", var_type="list", default_is_none=True, do_print=False
|
||||||
)
|
)
|
||||||
|
self.orphaned["max_orphaned_files_to_delete"] = self.util.check_for_attribute(
|
||||||
|
self.data,
|
||||||
|
"max_orphaned_files_to_delete",
|
||||||
|
parent="orphaned",
|
||||||
|
var_type="int",
|
||||||
|
default=50,
|
||||||
|
min_int=-1,
|
||||||
|
)
|
||||||
if self.commands["rem_orphaned"]:
|
if self.commands["rem_orphaned"]:
|
||||||
exclude_orphaned = f"**{os.sep}{os.path.basename(self.orphaned_dir.rstrip(os.sep))}{os.sep}*"
|
exclude_orphaned = f"**{os.sep}{os.path.basename(self.orphaned_dir.rstrip(os.sep))}{os.sep}*"
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ class Category:
|
||||||
new_cat.extend(self.get_tracker_cat(torrent) or self.qbt.get_category(torrent.save_path))
|
new_cat.extend(self.get_tracker_cat(torrent) or self.qbt.get_category(torrent.save_path))
|
||||||
if not torrent.auto_tmm and torrent_category:
|
if not torrent.auto_tmm and torrent_category:
|
||||||
logger.print_line(
|
logger.print_line(
|
||||||
f"{torrent.name} has Automatic Torrent Management disabled and already has a category"
|
f"{torrent.name} has Automatic Torrent Management disabled and already has the category"
|
||||||
f"{torrent_category}. Skipping..",
|
f" {torrent_category}. Skipping..",
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,9 @@ class RemoveOrphaned:
|
||||||
for fullpath in fullpathlist
|
for fullpath in fullpathlist
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
root_files_set = set(root_files.result())
|
||||||
orphaned_files = set(root_files.result()) - set(torrent_files)
|
torrent_files_set = set(torrent_files)
|
||||||
|
orphaned_files = root_files_set - torrent_files_set
|
||||||
|
|
||||||
if self.config.orphaned["exclude_patterns"]:
|
if self.config.orphaned["exclude_patterns"]:
|
||||||
logger.print_line("Processing orphan exclude patterns")
|
logger.print_line("Processing orphan exclude patterns")
|
||||||
|
|
@ -59,7 +60,18 @@ class RemoveOrphaned:
|
||||||
|
|
||||||
orphaned_files = set(orphaned_files) - set(excluded_orphan_files)
|
orphaned_files = set(orphaned_files) - set(excluded_orphan_files)
|
||||||
|
|
||||||
if orphaned_files:
|
# Check the threshold before deleting orphaned files
|
||||||
|
max_orphaned_files_to_delete = self.config.orphaned.get("max_orphaned_files_to_delete")
|
||||||
|
if len(orphaned_files) and len(orphaned_files) > max_orphaned_files_to_delete and max_orphaned_files_to_delete != -1:
|
||||||
|
e = (
|
||||||
|
f"Too many orphaned files detected ({len(orphaned_files)}). "
|
||||||
|
f"Max Threshold for deletion is set to {max_orphaned_files_to_delete}. "
|
||||||
|
"Aborting deletion to avoid accidental data loss."
|
||||||
|
)
|
||||||
|
self.config.notify(e, "Remove Orphaned", False)
|
||||||
|
logger.warning(e)
|
||||||
|
return
|
||||||
|
elif orphaned_files:
|
||||||
orphaned_files = sorted(orphaned_files)
|
orphaned_files = sorted(orphaned_files)
|
||||||
os.makedirs(self.orphaned_dir, exist_ok=True)
|
os.makedirs(self.orphaned_dir, exist_ok=True)
|
||||||
body = []
|
body = []
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue