Sonarr/Sonarr — pull request #139 by Taloth (2014-11-15 22:24:20+00:00)
Title: Verified file transfer

Episode moves now include filesize checks.
Basically the procedure is as follows:
- If a hardlink was requested, try the hardlink first revert to copy if that fails. (this is what was done already)
- If a copy, do the copy and compare the filesizes, retry 2 times if wrong, throws IOException if it still fails.
- If a move a couple of steps:
1) make a hardlink to '{filename}.movebackup' in same directory. If fails, skip to 3.
2) Move that backup file to the destination and compare the filesizes. If succeeds, delete original and exit.
3) Delete backup file if created. Then do a Copy like before, 2 retries at the most.
4) Delete original if succeeded, throw IOException if failed.

The goal of this procedure is to detect CIFS errors. Another method would be to revert to read and write the file streams from .net directly, to append missing bytes, but I didn't want to do that at this point.
So if a copy fails, delete the partial destination and retry, instead of appending the missing bytes.

I had to include 1 commit from the torrent branch which adds hardlink support.

I opted to create a separate service for all this instead of embedding it in the DiskProvider, mainly because this makes it possible to have unit tests for it.