Open vancrize opened 1 month ago
After looking into the script and trying to understand it i would try to use os.link for this and rely on the rest of the script for path finding and creating, just intercepting the actual move.
The way i would do it is to add a config flag for a hardlink operation instead of moving, which will influence the functions that modify/move/delete the actual file via simple if/else
Don't know how soon i can approach it, but will come back here to look for suggestions or give a status of how its working.
I did it. Please excuse my poor execution. I just wanted it to make it work.
Basically i created a flag use_hardlinks
in config.py
:
https://gist.github.com/vancrize/97407bc098a240587cfe27b8f6653030#file-config-py
I then went to the main file renamerOnUpdate.py
and prevented all DB operations and OS and file system interactions based on a simple if statement and let the script do nothing instead. The actual file move is changed to a link creation while checking if the link already exists, adding that information to the log.
The DB Operations are suppressed because adding the new path to the scene in Stash leads to a whole new rats nest of things that can go wrong in the future. Basically i let Stash handle the source file as the single truth that it is. This will lead to reindexing the hard link and creating duplicates if both the file and the hard link are indexed. Keep this in mind when handling with dupes or working with path based filters.
I will leave it here for documentation. Look for the lines around config.use_hardlinks
to see the changes. It will either suppress or add a operation.
https://gist.github.com/vancrize/97407bc098a240587cfe27b8f6653030#file-renameronupdate-py
I wonder if it is possible to let the script create hard links according to the existing renaming ruleset based on tags etc.
After renaming a bunch of loose files very neatly with the help of the script i ran into a roadblock with several TB of permaseeded files in P2P. Because other apps outside Stash & qB are set upto work with the final naming convention i wondered how i can get the files into the workflow without renaming or moving them actually.
I am aware that hardlinks should happen on the same mount and it would apply in my and i think most of the cases.
e.g. based on my case:
"/VR/Library/Unsorted/original_a.mp4" -> "/VR/Library/Organized/StructuredA/renamed_a.mp4" "/VR/Library/Unsorted/original_b.mp4" -> "/VR/Library/Organized/StructuredB/renamed_b.mp4" "/VR/Library/Unsorted/original_c.mp4" -> "/VR/Library/Organized/StructuredB/renamed_c.mp4" "/VR/Library/Unsorted/original_d.mp4" -> "/VR/Library/Organized/StructuredC/renamed_d.mp4"
We have the new location and we have the new filename. In my imagination it should be the matter of creating the folders like they are created now and only running the
ln
command after this, right?Edit: I linked some files manually from inside the stash container and after creating the folders before, the link succeeded and worked in my other containers just as i wanted.
Is this theoretically possible from inside the script? I have experience in python, but not so much in the whole Unraid/Docker/Filesystem topics, but would like to look into it.