tfeldmann / organize

The file management automation tool.
http://organize.readthedocs.io
MIT License
2.32k stars 134 forks source link

Moving a file to a NAS server triggers an error #373

Open robolth opened 7 months ago

robolth commented 7 months ago

Moving a file to a NAS Server triggers an error. The file is copied, but the original is not removed. This did not happen with v2. I believe this is the same issue as in this SO thread: https://stackoverflow.com/questions/18621577/errno-22-with-python-shutil-and-move-function

Output of organize run:

⚙ Rule #0: Move file to NAS volume
 ──────────
/Users/user/Downloads/file.txt
    - (move) Move to /Volumes/NAS-volume/file.txt
    - (move) ERROR! [('/Users/user/Downloads/file.txt', '/Volumes/NAS-volume/file.txt', "[Errno 22] 
Invalid argument: '/Volumes/NAS-volume/file.txt'")]

Please note that the file has been copied to the NAS volume despite the error. The original, however, has not been removed.

Your config file

rules:
  - name: "Move file to NAS volume"
    locations: "/Users/user/Downloads/"
    subfolders: false
    filters:
      - extension: txt
    actions:
      - move:
          dest: "/Volumes/NAS-volume/"
          on_conflict: "skip"
nodecentral commented 7 months ago

Hi @robolth - sorry I don’t want to hijack this thread, but I have a very similar issue, although by the looks of it I’m on v2.4 not v3 - I’m trying to move a txt from one location on a mapped volume to another. All I get is permissions errors (even though both users seem to be in the same group (1000), and both the file & directory have r-w, rwx, r-- permissions.

What user, group and permissions do you have on the elements involved in your error ?

robolth commented 7 months ago

Hi, here are the permissions of my NAS volume: drwx------ For more details: I'm on macOS 14.4.1 I did not have this issue prior to updating to organize v3.

tfeldmann commented 7 months ago

Thanks for reporting. I'm struggling reproducing this. Did you find anything strange with the paths shown (I guess '/Users/user/Downloads/file.txt', '/Volumes/NAS-volume/file.txt' are placeholders) like spaces, special characters or wrong slashes?

robolth commented 7 months ago

Thanks for investigating this. They're placeholders, you're right; however I've juste reproduced it with a tailor-made rule and txt file:

/Users/test-user
  ./file.txt
    - (move) Move to /Volumes/test-volume/file.txt
    - (move) ERROR! [Errno 22] Invalid argument: '/Volumes/test-volume/file.txt'

These are the real volume and file names and paths: only special character is -.

I don't know why there is a newline and a . in the destination folder, the real path is /Users/billet-cleanly/file.txt, however this is also the case fo the output of other rules with no issue.

Edit: as a last test, I also tried to simply move it on the Mac hard drive rather than on the NAS, this time without any issue, so it really seems to be caused by the NAS.

tfeldmann commented 7 months ago

Can you try moving the files manually using the following script:

import argparse
import shutil
from pathlib import Path

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("src", type=Path)
    parser.add_argument("dst", type=Path)
    parser.add_argument("--simple", action="store_true")

    args = parser.parse_args()
    src = str(args.src.resolve())
    dst = str(args.dst.resolve())

    print(f"Moving {src} to {dst}")

    if args.simple:
        shutil.move(src, dst, copy_function=shutil.copy)
    else:
        shutil.move(src, dst)

Please try both moving methods with python3 movescript.py sourcefile destfile and python3 movescript.py sourcefile destfile --simple.

Organize uses the same method of moving so that would be super helpful.

robolth commented 7 months ago

Just tried it: it works with both methods without any issue.

tfeldmann commented 7 months ago

That’s great! We’re getting closer. Does organize fail on symlinks or symlinked folders? It might be a missing ‘resolve‘ on the target.

robolth commented 7 months ago

I'm not sure how I can check whether this is the case. Here is a ls -l on the target folder:

user@user-computer / % ls -al /Users/user/Library/Mobile\ Documents/com~apple~CloudDocs/Downloads
total 1720
-rw-r--r--@ 1 billet-cleanly  staff  0 26 nov 18:58 Icon?

Does that help?

tfeldmann commented 7 months ago

Ah so the target is the iCloud Drive folder? Is it failing on both iCloud Drive and the network volume? Did you grant your terminal the permission to read iCloud in your system settings?

robolth commented 7 months ago

Yes, it's the iCloud Drive folder. It's not failing on the target iCloud Drive subfolder (since it successfully copy files from there to the network volume, and is also able to trash them afterwards). The only problem is on the actual network drive, where it can copy files but not move them. I did check: I granted terminal permission to read iCloud on the system settings.

I might be wrong, but I believe the issue is the same as the one depicted here: https://stackoverflow.com/questions/18621577/errno-22-with-python-shutil-and-move-function