Drazzilb08 / daps

DAPS (Drazzilb's Arr PMM Scripts) A collection of useful scripts for media management and automation
MIT License
152 stars 31 forks source link

Handle sym links in rename_files function #191

Closed Heavybullets8 closed 1 month ago

Heavybullets8 commented 1 month ago
  1. Use os.path.lexists() Instead of os.path.isfile():

    • os.path.isfile() returns False for broken symlinks. Switching to os.path.lexists() ensures that both existing files and symlinks (including broken ones) return True.
  2. Remove Existing Files Before Creating Links:

    • Before invoking os.link() or os.symlink(), the script now checks if the target path exists using os.path.lexists(). If it does, and the action is to create a symlink or hardlink, the existing file is removed since os.symlink() and os.link() do not overwrite destination files.
  3. Handle Broken Symlinks:

    • The file comparison is moved into a try block. If a broken symlink is encountered (raising a FileNotFoundError), the script removes it so the new link can be made.

Testing

Tested the updated script on my machine, which resolved the issue where new posters were not replacing existing ones due to existing files. Hopefully these changes can get us closer to having support for symlink and hardlink action types.

Drazzilb08 commented 1 month ago

Let me look this over and I'll get back to you. Might be a bit due to life being what it is right now.

Heavybullets8 commented 1 month ago

No problem at all! Hope things are going well. If you need anything lmk brother.

Also if you need to checkout my test env (well actually its in prod) its in my kubernetes repo: https://github.com/Heavybullets8/heavy-ops/blob/main/kubernetes/apps/media/plex/daps/overwrite/poster_renamerr.py https://github.com/Heavybullets8/heavy-ops/blob/main/kubernetes/apps/media/plex/daps/config/config.yaml

If anything needs to be changed to a specific style or anything just lmk or make the changes yourself if you would prefer. Cheers man.