fix empty dir
This commit is contained in:
@@ -356,8 +356,11 @@ def _annotate_path_directories(profile: dict, payload: dict) -> dict:
|
|||||||
for item in dirs:
|
for item in dirs:
|
||||||
item_path = item.get("path") or ""
|
item_path = item.get("path") or ""
|
||||||
has_torrents = _path_has_cached_torrents(int(profile.get("id") or 0), item_path)
|
has_torrents = _path_has_cached_torrents(int(profile.get("id") or 0), item_path)
|
||||||
|
is_empty = bool(item.get("empty"))
|
||||||
item["has_torrents"] = has_torrents
|
item["has_torrents"] = has_torrents
|
||||||
item["can_rename"] = bool(item.get("empty")) and not has_torrents
|
item["can_rename"] = is_empty and not has_torrents
|
||||||
|
# Note: The picker exposes a short reason so disabled rename buttons explain the safety rule.
|
||||||
|
item["rename_reason"] = "Rename folder" if item["can_rename"] else ("Folder contains a known torrent path" if has_torrents else "Only empty folders can be renamed")
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ def browse_path(profile: dict, path: str | None = None) -> dict:
|
|||||||
'dir_count=0; file_count=0; '
|
'dir_count=0; file_count=0; '
|
||||||
'for p in "$base"/* "$base"/.[!.]* "$base"/..?*; do '
|
'for p in "$base"/* "$base"/.[!.]* "$base"/..?*; do '
|
||||||
'[ -e "$p" ] || continue; '
|
'[ -e "$p" ] || continue; '
|
||||||
'if [ -d "$p" ]; then dir_count=$((dir_count+1)); name=${p##*/}; printf "D\\t%s\\t%s\\n" "$name" "$p"; '
|
'if [ -d "$p" ]; then '
|
||||||
|
'dir_count=$((dir_count+1)); name=${p##*/}; empty=1; '
|
||||||
|
'if find "$p" -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null | grep -q .; then empty=0; fi; '
|
||||||
|
'printf "D\\t%s\\t%s\\t%s\\n" "$name" "$p" "$empty"; '
|
||||||
'elif [ -f "$p" ]; then file_count=$((file_count+1)); fi; '
|
'elif [ -f "$p" ]; then file_count=$((file_count+1)); fi; '
|
||||||
'done; '
|
'done; '
|
||||||
'printf "M\\t%s\\t%s\\n" "$dir_count" "$file_count"; '
|
'printf "M\\t%s\\t%s\\n" "$dir_count" "$file_count"; '
|
||||||
@@ -37,9 +40,12 @@ def browse_path(profile: dict, path: str | None = None) -> dict:
|
|||||||
continue
|
continue
|
||||||
marker, rest = line.split("\t", 1)
|
marker, rest = line.split("\t", 1)
|
||||||
if marker == "D" and "\t" in rest:
|
if marker == "D" and "\t" in rest:
|
||||||
name, full_path = rest.split("\t", 1)
|
parts = rest.split("\t", 2)
|
||||||
|
name, full_path = parts[0], parts[1]
|
||||||
|
is_empty = len(parts) > 2 and parts[2] == "1"
|
||||||
if name not in {".", ".."}:
|
if name not in {".", ".."}:
|
||||||
dirs.append({"name": name, "path": full_path})
|
# Note: Empty status is returned with every directory so the path picker can enable safe inline rename.
|
||||||
|
dirs.append({"name": name, "path": full_path, "empty": is_empty})
|
||||||
elif marker == "M" and "\t" in rest:
|
elif marker == "M" and "\t" in rest:
|
||||||
first, second = rest.split("\t", 1)
|
first, second = rest.split("\t", 1)
|
||||||
try:
|
try:
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user