Skip to content

clarify a bit of obtuse logic

anarcat requested to merge obtuse into main

I was getting weird output from the script when trying to diagnose a blocked dangerbot (e.g. #17 (closed) or #18). I couldn't figure out what was going on and went to look at the code, then ended up staring at this line for 2 minutes:

    # non-empty folder or regular file
    if len(listing) > 1 or not path.endswith("/"):

It stuck with me. I couldn't actually remember (let alone figure out) what that was supposed to do. I was so confused I actually ended up re-proving De Morgan's Laws:

https://en.wikipedia.org/wiki/De_Morgan%27s_laws

The gist of the change is that we change this:

    logging.info("sanitizing %s %s", folder, path)
    # non-empty folder or regular file
    if len(listing) > 1 or not path.endswith("/"):
        # [...] do everything

To this:

   if path.endswith("/") and len(listing) <= 1:
        logging.info("skipping empty folder: %s/%s", folder, path)
        return
   logging.info("sanitizing %s %s", folder, path)
   # [...] do everything

The diff looks huge because we reindent the entire "# [...] do everything" block, but it's otherwise basically a noop, except we have a better error message.

The output before:

anarcat@curie:dangerzone-webdav-processor(main)$ ./dangerzone-webdav-processor -l https://nc.torproject.net/remote.php/dav/files/dangerzone-bot/ -u dangerzone-bot -n  -v
authenticated with webdav https://nc.torproject.net/remote.php/dav/files/dangerzone-bot/
sanitizing CVs (4)/ Candidate 33/
sanitizing CVs (4)/ Candidate 35/

after:

anarcat@curie:dangerzone-webdav-processor(main)$ ./dangerzone-webdav-processor -l https://nc.torproject.net/remote.php/dav/files/dangerzone-bot/ -u dangerzone-bot -n  -v
authenticated with webdav https://nc.torproject.net/remote.php/dav/files/dangerzone-bot/
skipping empty folder: CVs (4)//Candidate 33/
skipping empty folder: CVs (4)//Candidate 35/
Edited by anarcat

Merge request reports