unioslo / tsd-api-client

Command line client for the TSD HTTP API
BSD 3-Clause "New" or "Revised" License
13 stars 5 forks source link

Error downloading directory with names with only one character #138

Open torben-uio opened 3 months ago

torben-uio commented 3 months ago

When I try to download a directory named with only one character e.g "0" or "a", tacl throws an error (see below) and nothing gets downloaded. However, I can download without problems after renaming the directory on TSD to "dir0" etc. (I haven't tried with directories with two or three character names.)

$ tacl pXXX --verbose --download 0

DEBUG using login session with prod:pXXX:export

DEBUG checking if login session has expired

DEBUG found token: ****************************

DEBUG session has not expired

DEBUG checking if login session will expire soon

DEBUG session will not expire soon

DEBUG using token from existing login session

DEBUG using refresh token from existing login session

DEBUG refreshes remaining: 64

DEBUG ************************

DEBUG starting file export
downloading directory: 0

DEBUG reading from cache
resuming directory transfer from cache

DEBUG creating directory: 
Traceback (most recent call last):
  File "/uio/platon/med-klinmed-u1/******/.local/bin/tacl", line 8, in <module>
    sys.exit(cli())
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/tsdapiclient/tacl.py", line 729, in cli
    downloader.sync()
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/tsdapiclient/sync.py", line 306, in sync
    self._transfer(resource, integrity_reference=integrity_reference)
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/tsdapiclient/sync.py", line 683, in _transfer
    resource = self._transfer_remote_to_local(
  File "/uio/platon/med-klinmed-u1/******/.local/lib/python3.9/site-packages/tsdapiclient/sync.py", line 512, in _transfer_remote_to_local
    os.makedirs(target)
  File "/usr/lib64/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
haatveit commented 1 month ago

Hi, thanks for reporting the issue.

I did not manage to reproduce this with downloading a directory named 0 on the latest tsd-api-client running under Python 3.12.

❯ tacl --version
tacl v3.5.14
- OS/Arch: Darwin/arm64
- Python: 3.12.3

Did another test on Python 3.9, but couldn't reproduce it there either.

In the debug output you've provided, it's trying to resume the transfer from cache, which wasn't happening in my initial two tests. I also interrupted tacl mid-transfer and restarted the process to force it to resume "directory transfer from cache" as in your case, but this still did not cause any issue and my transfers finished successfully.

tacl provides a parameter for deleting its download cache, can you attempt to wipe it and see if the problem persists? tacl pXXX --download-cache-delete-all. There's also the option of wiping only a specific cache:

❯ tacl --help | grep download-cache
  --download-cache-show         View the request cache
  --download-cache-delete TEXT  Delete a request cache for a given key
  --download-cache-delete-all   Delete the entire request cache

If wiping the cache and the problem still exists, can you please try to upgrade to tsd-api-client 3.5.14 and verify that it's reproducible there as well? I'm not sure which version you were using at the time of reporting this issue, so it would help in narrowing down the scope.