Ensure hash checking a file is a purely read-only operation #674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original implementation had some conveniences which are not great in certain circumstances. The DiskManager implementation would do it's utmost to ensure files were always the correct size/length, and that zero length files always existed on disk.
This is fine except if someone wishes to check if a particular file matches a particular hash - in this scenario, while they simply wanted to see if there was a match, the act of running the hashcheck would also truncate the file if it were too large.
Now the engine doesn't do this, and
TorrentManager.HashCheckAsync
neither truncates, nor creates zero length files.If someone takes the step of actually calling
TorrentManager.StartAsync
, this is a clear sign they really do want to download the torrent, and at that point zero length files will be created, and existing files will be truncated if they are too large. This operation occurs only during the 'Starting' phase, prior to enter 'Downloading' or 'Seeding'. This makes things a little easier to reason about :)However, to support this in the optimal way additional methods need to be added to some of the interfaces used for IO, such as a get/set length method.