Delete all ButSystem data from storage. Admin-only, requires creds.
()
| 12322 | old_rel, new_rel = safe_relpath(old_rel), safe_relpath(new_rel) |
| 12323 | with FILE_META_LOCK: |
| 12324 | conn = db_connect() |
| 12325 | for table in ("file_comments", "file_shares"): |
| 12326 | rows = conn.execute(f"SELECT id, relpath FROM {table} WHERE owner=? AND (relpath=? OR relpath LIKE ?)", (owner, old_rel, old_rel + "/%")).fetchall() |
| 12327 | for row in rows: |
| 12328 | suffix = row["relpath"][len(old_rel):] |
| 12329 | conn.execute(f"UPDATE {table} SET relpath=? WHERE id=?", (new_rel + suffix, row["id"])) |
| 12330 | conn.commit(); conn.close() |
| 12331 | |
| 12332 | |
| 12333 | def _parse_date_start(value: str) -> Optional[float]: |
| 12334 | try: |
| 12335 | return datetime.strptime(value, "%Y-%m-%d").timestamp() if value else None |
| 12336 | except Exception: |
| 12337 | return None |
| 12338 | |
| 12339 | |
| 12340 | def _parse_date_end(value: str) -> Optional[float]: |
| 12341 | try: |
| 12342 | return (datetime.strptime(value, "%Y-%m-%d") + timedelta(days=1)).timestamp() if value else None |
| 12343 | except Exception: |
| 12344 | return None |
| 12345 | |
| 12346 | |
| 12347 | def list_dir_entries(username: str, rel: str, sort: str = "name", order: str = "asc", query: str = "", category: str = "all", size_min: int = 0, size_max: Optional[int] = None, date_from_ts: Optional[float] = None, date_to_ts: Optional[float] = None): |
| 12348 | rel = safe_relpath(rel) |
| 12349 | base = abs_user_path(username, rel) |
| 12350 | os.makedirs(base, exist_ok=True) |
| 12351 | if not os.path.isdir(base): |
| 12352 | raise ValueError("Not a directory") |
| 12353 | query_cf = (query or "").strip().casefold() |
| 12354 | rows = [] |
| 12355 | if query_cf: |
| 12356 | iterator = [] |
| 12357 | for current, dirs, files_ in os.walk(base, followlinks=False): |
| 12358 | dirs[:] = [d for d in dirs if not os.path.islink(os.path.join(current, d))] |
| 12359 | for name in dirs + files_: |
| 12360 | iterator.append((current, name)) |
| 12361 | else: |
| 12362 | iterator = [(base, name) for name in os.listdir(base)] |
| 12363 | user_base = user_root(username) |
| 12364 | for current, name in iterator: |
| 12365 | full = os.path.join(current, name) |
| 12366 | try: |
| 12367 | if os.path.islink(full): |
| 12368 | continue |
| 12369 | st = os.stat(full) |
| 12370 | except Exception: |
| 12371 | continue |
| 12372 | is_dir = os.path.isdir(full) |
| 12373 | item_rel = os.path.relpath(full, user_base).replace(os.sep, "/") |
| 12374 | parent_rel = os.path.dirname(item_rel).replace(os.sep, "/") |
| 12375 | cat = _file_category(name, is_dir) |
| 12376 | if query_cf and query_cf not in name.casefold() and query_cf not in item_rel.casefold(): |
| 12377 | continue |
| 12378 | if category != "all" and cat != category: |
| 12379 | continue |
| 12380 | if not is_dir: |
| 12381 | if st.st_size < max(0, int(size_min or 0)): |
nothing calls this directly
no test coverage detected