Check free space before downloading #3631
Merged
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.
Motivation
Users periodically report issues with running out of disk space. (Given how cheap storage is these days, we can only credit the extremely creative developers of planet packs for taking up so many gigabytes with their beautiful textures.) This can happen at three points:
%TEMP%
folder, which can fill upCurrently CKAN does not attempt to handle or prevent this. The exception is simply thrown and the user gets to read a stack trace.
Previous investigations
Last time I looked at this I hit a speedbump due to the lack of a built-in mapping from directories to drives in .NET, which is probably because of cross-platform considerations. Whereas on Windows, all
DriveInfo.RootDirectory.FullName
properties return something likeC:\
,D:\
, etc., on Unix these can be just about any path since Unix is much more flexible regarding where you can mount devices. The logic needs to work for both.Considered and not done
It would be nice to catch and handle these exceptions. Unfortunately, they're generic
IOException
s rather than something specific to disk space, and there's no programmatic way to check whether the exception relates to disk space. So we would be catching a lot of other unrelated exceptions in the same spot, and we would not be able to generate a useful error message from them.Changes
DirectoryInfo.GetDrive()
to return theDriveInfo
object associated with a folder. It works by comparing (case-insensitive on Windows) the pieces of theFullName
properties of the given dir andDriveInfo.RootDirectory
. Empty pieces are pruned to make sure"C:\\".Split("\\")
doesn't return["C:", ""]
which would fail to match a longer path without a blank piece in that position.CKANPathUtils
isstatic
(it always should have been, just an oversight)CKANPathUtils.CheckFreeSpace
uses the new.GetDrive()
to check the free space of a given folder and throws an instance of new classNotEnoughSpaceKraken
if it isn't enough, with a custom error message, which GUI catches and pretty-prints in the install logCheckFreeSpace
in the game dir before installing, using theinstall_size
metadata from Add install size to metadata and display in clients #3568CheckFreeSpace
in the temp dir and the cache dir before downloadingCheckFreeSpace
in the game dir again after the downloads complete, just in case the game dir and cache dir are on the same deviceCkanModule.FmtSize
goes up to TiB rather than just GiB, since we're going to be reporting disk sizesckan cache list
prints the free space of your cache's deviceThis will alert users to disk space problems earlier in the install flow so they can free up space in response to a friendlier message.
Fixes #3581.