Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check free space before downloading #3631

Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Aug 16, 2022

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:

  • The downloader downloads ZIP files to the %TEMP% folder, which can fill up
  • Then it copies/moves downloaded files into the cache folder, which can fill up
  • Then the installer extracts mod content from the ZIPs into the game folder, which can fill up

Currently 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 like C:\, 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 IOExceptions 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

  • Now a new extension method allows DirectoryInfo.GetDrive() to return the DriveInfo object associated with a folder. It works by comparing (case-insensitive on Windows) the pieces of the FullName properties of the given dir and DriveInfo.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.
  • Now CKANPathUtils is static (it always should have been, just an oversight)
  • Now CKANPathUtils.CheckFreeSpace uses the new .GetDrive() to check the free space of a given folder and throws an instance of new class NotEnoughSpaceKraken if it isn't enough, with a custom error message, which GUI catches and pretty-prints in the install log
  • Now we CheckFreeSpace in the game dir before installing, using the install_size metadata from Add install size to metadata and display in clients #3568
  • Now we CheckFreeSpace in the temp dir and the cache dir before downloading
  • Now we CheckFreeSpace in the game dir again after the downloads complete, just in case the game dir and cache dir are on the same device
  • Now CkanModule.FmtSize goes up to TiB rather than just GiB, since we're going to be reporting disk sizes
  • Now ckan cache list prints the free space of your cache's device
  • Now GUI's settings window also shows the free space of the cache dir

This 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.

image

image

image

@HebaruSan HebaruSan added Enhancement GUI Issues affecting the interactive GUI Cmdline Issues affecting the command line Core (ckan.dll) Issues affecting the core part of CKAN Pull request Network Issues affecting internet connections of CKAN labels Aug 16, 2022
Copy link
Member

@techman83 techman83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, that looks good. Disk handling can be a chore, so nice work!

@HebaruSan HebaruSan merged commit 1d4b745 into KSP-CKAN:master Aug 17, 2022
@HebaruSan HebaruSan deleted the feature/show-and-check-free-space branch August 17, 2022 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmdline Issues affecting the command line Core (ckan.dll) Issues affecting the core part of CKAN Enhancement GUI Issues affecting the interactive GUI Network Issues affecting internet connections of CKAN Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled Exception: Not Enough Space on Disk
2 participants