Search code examples
pythonmc

Is there a command to move file pointers across unRAID shares on the same drive?


I've created a Python script to help manage my media on an unRAID server. New files are automatically transferred into a folder and the script uses the folder structure and filenames to determine where they should be moved, usually into another share on the same drive. With Midnight Commander, this transfer happens instantly. This process in Explorer or my script using shutil.move() copies the file then deletes the original, which can take a long time for big files and also creates unnecessary read/writes on the drive. It's instant in both Explorer and Python when the transfer is on the same share.

Simplified pseudocode - Transfer and TV are shares on the same disk in this example:

from shutil import move

oldPath = r'\\NAS\Transfer\incoming\test.mkv'
newPath = r'\\NAS\TV\test.mkv'

move(oldPath, newPath)

Is there a way to move the file's pointer with Python, as I assume MC is doing, instead of physically moving the file?


Solution

  • The underlying interface for giving a file a new name while keeping it on the same filesystem is os.rename(). If that call fails, an in-place rename will not be possible.

    If you tested that an efficient local rename is possible directly on the file server, but not over your network share, you may be disregarding a limitation of your network filesystem (or how it's configured; make sure both source and destination are under the same mount point from the client's perspective, not just the server's).