Drone gives error when trying to upgrade hardlinked file

Hi
Just had a small issue with repack/proper downloading when using hard links. An error happened when trying to import the repack saying that the original file was still in use (the non repack version). This was probably because it was still seeding at the time.

[code]
Couldn’t import episode D:\Torrent\Complete\TV Shows\Witches.of.East.End.S02E08.REPACK.HDTV.x264-KILLERS[rarbg]\Witches.of.East.End.S02E08.REPACK.HDTV.x264-KILLERS.mp4: The process cannot access the file ‘D:\TV Shows\Witches of East End\Season 2\Witches of East End - S02E08 - Sex, Lies, and Birthday Cake.mp4’ because it is being used by another process.

System.IO.IOException: The process cannot access the file ‘D:\TV Shows\Witches of East End\Season 2\Witches of East End - S02E08 - Sex, Lies, and Birthday Cake.mp4’ because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at NzbDrone.Common.Disk.DiskProviderBase.DeleteFile(String path) in m:\BuildAgent2\work\328d72309b633a8\src\NzbDrone.Common\Disk\DiskProviderBase.cs:line 222
at NzbDrone.Core.MediaFiles.RecycleBinProvider.DeleteFile(String path) in m:\BuildAgent2\work\328d72309b633a8\src\NzbDrone.Core\MediaFiles\RecycleBinProvider.cs:line 85
at NzbDrone.Core.MediaFiles.UpgradeMediaFileService.UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode, Boolean copyOnly) in m:\BuildAgent2\work\328d72309b633a8\src\NzbDrone.Core\MediaFiles\UpgradeMediaFileService.cs:line 52
at NzbDrone.Core.MediaFiles.EpisodeImport.ImportApprovedEpisodes.Import(List`1 decisions, Boolean newDownload, DownloadClientItem historyItem) in m:\BuildAgent2\work\328d72309b633a8\src\NzbDrone.Core\MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs:line 85[/code]

How do you replace files in nzbdrone - do you overwrite the previous file or delete it and then move/copy/hard link the new one?

If you try to overwrite a hard link (say in the tv show directory) it appears to edit the original file in the download directory too (either causing an error with seeding or failing to overwrite because the file is in use by seeding).
Deleting the file in the tv show directory and then creating a new hard link will be a better solution when replacing files.

Everything else has been working pretty solidly the last week or so for me :stuck_out_tongue:

This is exactly what we meant with the warning that ‘should’ show near the settings (I believe its not visible due to a UI glitch), so lemme copy paste:
“Occassionally, file locks may prevent renaming files that are currently seeding. Temporarily disable seeding while using the Rename UI to rename existing episodes to work around it.”

Basically, your torrent client has a lock on the original file, which on windows prevents the hardlink to be removed. You read it correctly, it prevents a link to be removed. Drone doesn’t replace file content, it replaces the file. In this case it tries to delete the link.
There is absolutely nothing we can do about that, it’s an OS limitation.

To explain the issue from a more technical point of view: There are 3 different locks, Write, Read, Delete.
The Write lock prevents other programs from writing. When a file is opened for write, this lock is used by default, unless specified otherwise.
The Read lock prevents other programs from reading. When a program opens a file, it has to specify this explicitly, it’s not enabled by default.
The Delete lock prevents other programs from deleting the file. On Windows this is enabled by default, so if a program has a file open, you cannot delete it. On Linux this lock is NOT enabled by default, even when it’s open for writing, allowing other programs to delete the file, even though the first program is writing it.

This difference is what’s causing your problem.
It would take effort by the torrent client to explicitly open the file without the delete lock on windows.

Anyway, I hope that answers the question.

1 Like

Thanks Taloth, please check out this thread that I’ve been engaged in with Clinton Hall (nzbtomedia) as he has come up with a possible solution for this: https://github.com/clinton-hall/nzbToMedia/issues/574

I realize this isn’t high priority to fix. But I think getting the torrent branch working for handling repacks/propers and higher quality replacements should definitely make the list if it is indeed possible to fix. Otherwise there could be potentially a lot of manual operations required by users depending on the amount of times this situation occurs.