kh
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -110,7 +110,31 @@ class Delete_File(sh.Cmdlet):
|
||||
store = sh.get_field(item, "store")
|
||||
|
||||
store_lower = str(store).lower() if store else ""
|
||||
is_hydrus_store = bool(store_lower) and ("hydrus" in store_lower or store_lower in {"home", "work"})
|
||||
|
||||
backend = None
|
||||
try:
|
||||
if store:
|
||||
registry = Store(config)
|
||||
if registry.is_available(str(store)):
|
||||
backend = registry[str(store)]
|
||||
except Exception:
|
||||
backend = None
|
||||
|
||||
# Determine whether the store backend is HydrusNetwork.
|
||||
# IMPORTANT: Hydrus instances are named by the user (e.g. 'home', 'rpi'),
|
||||
# so checking only the store name is unreliable.
|
||||
is_hydrus_store = False
|
||||
try:
|
||||
if backend is not None:
|
||||
from Store.HydrusNetwork import HydrusNetwork as HydrusStore
|
||||
|
||||
is_hydrus_store = isinstance(backend, HydrusStore)
|
||||
except Exception:
|
||||
is_hydrus_store = False
|
||||
|
||||
# Backwards-compatible fallback heuristic (older items might only carry a name).
|
||||
if (not is_hydrus_store) and bool(store_lower) and ("hydrus" in store_lower or store_lower in {"home", "work"}):
|
||||
is_hydrus_store = True
|
||||
store_label = str(store) if store else "default"
|
||||
hydrus_prefix = f"[hydrusnetwork:{store_label}]"
|
||||
|
||||
@@ -128,9 +152,13 @@ class Delete_File(sh.Cmdlet):
|
||||
# via the backend API. This supports store items where `path`/`target` is the hash.
|
||||
if conserve != "local" and store and (not is_hydrus_store):
|
||||
try:
|
||||
registry = Store(config)
|
||||
if registry.is_available(str(store)):
|
||||
backend = registry[str(store)]
|
||||
# Re-use an already resolved backend when available.
|
||||
if backend is None:
|
||||
registry = Store(config)
|
||||
if registry.is_available(str(store)):
|
||||
backend = registry[str(store)]
|
||||
|
||||
if backend is not None:
|
||||
|
||||
# Prefer hash when available.
|
||||
hash_candidate = sh.normalize_hash(hash_hex_raw) if hash_hex_raw else None
|
||||
@@ -140,7 +168,8 @@ class Delete_File(sh.Cmdlet):
|
||||
resolved_path = None
|
||||
try:
|
||||
if hash_candidate and hasattr(backend, "get_file"):
|
||||
resolved_path = backend.get_file(hash_candidate)
|
||||
candidate_path = backend.get_file(hash_candidate)
|
||||
resolved_path = candidate_path if isinstance(candidate_path, Path) else None
|
||||
except Exception:
|
||||
resolved_path = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user