Skip to content

Commit

Permalink
cleaner error message
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer committed Sep 25, 2024
1 parent 9ef85ae commit 40c12ef
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions delayed_rm/delayed_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from tempfile import gettempdir
from datetime import datetime
from pathlib import Path
from os import environ
import subprocess
import argparse
import tempfile
import shutil
import time
import sys
import os


__version__ = "2.9.1"
__version__ = "2.9.2"


#
Expand Down Expand Up @@ -83,9 +83,8 @@ def _prep(paths: list[Path], rf: bool) -> list[Path]:
# Normalize paths and error checking
try:
paths = [i.parent.resolve(strict=True) / i.name for i in paths]
# pathlib.stat does not support follow_symlinks until 3.10
if len(paths) != len({os.stat(i, follow_symlinks=False).st_ino for i in paths}):
raise RMError("duplicate items passed")
if len(paths) != len({i.stat(follow_symlinks=False).st_ino for i in paths}):
raise RMError("duplicate or hardlinked items passed")
except (FileNotFoundError, RuntimeError) as e:
raise RMError(e) from e
for i in paths:
Expand Down Expand Up @@ -231,7 +230,7 @@ def delayed_rm_raw(delay: int, log: bool, r: bool, f: bool, paths: list[Path]) -


def main(prog: str, *args: str) -> bool:
base: str = os.path.basename(prog)
base: str = Path(prog).name
parser = argparse.ArgumentParser(prog=base)
parser.add_argument("--version", action="version", version=f"{base} {__version__}")
parser.add_argument("--delay", "--ttl", type=int, default=900, help="The deletion delay in seconds")
Expand Down Expand Up @@ -259,12 +258,12 @@ def cli() -> None:
def _secret_cli():
"""
This CLI is invoked on import and not will do nothing by default
This CLI will only active if argv was intentionally configured to do so
This CLI will only activate if argv was intentionally configured to do so
This entrypoint is for the spawned process to act
"""
try:
if len(sys.argv) == 4 and sys.argv[1] == _Secret.value:
if os.environ.get(_Secret.key, None) == _Secret.value:
if environ.get(_Secret.key, None) == _Secret.value:
delay = int(sys.argv[2])
d = Path(sys.argv[3]).resolve()
time.sleep(delay)
Expand Down

0 comments on commit 40c12ef

Please sign in to comment.