itchio / butler

🎩 Command-line itch.io helper
MIT License
745 stars 52 forks source link

Clearing files after Install.Cancel #205

Open hagabaka opened 4 years ago

hagabaka commented 4 years ago

When an installation is cancelled, the files are left on the disk. Later on if the game is reinstalled, butler will create a new directory like game-123456 2 instead of reusing the one from the previous attempt. Is there an easy way to remove files from cancelled installs, or reusing the same directory when installing the same game?

fasterthanlime commented 4 years ago

So, the problem here is that Install.Cancel is really more of a "pause install" endpoint. (Installing is an background operation, so "cancelling" it just means stop running that operation).

The itch app typically uses Install.Cancel to pause downloads. When a download is discarded, some additional cleanup happens, see:

https://github.com/itchio/butler/blob/da33ce94df142460d3e28172da74acdfd30d00ef/endpoints/downloads/downloads_drive.go#L134-L176

I'm not sure how that would be handled for a third-party client that doesn't use Downloads.Drive. I guess you could have similar logic in your application? You'd need to make sure that the download has actually stopped before you go ahead and wipe the install folder.

Another problem with Downloads.Drive-less usage is that downloads are never discarded, so, the download "queue" will keep growing (although hopefully with finished downloads).

Note that Downloads.Discard just marks the DB download record as "discarded", it doesn't cancel any running installs or clean any folders, the downloads driver does that.