Skip to content

Failed downloads leave partial files in the temp directory #163

Closed

Description

@roxblnfk

Description

When an asset download fails, the partial file stays in the temp directory. Each release DLoad falls back to leaves one more file behind.

The cleanup in Downloader::processAsset() (src/Module/Downloader/Downloader.php:480 on 1.x) passes the wrong path:

)->then(null, static function (\Throwable $e) use ($file): void {
    @\unlink($file->getPath());
    throw $e;
}));

SplFileObject::getPath() returns the directory, not the file, so unlink() targets the temp directory and fails, and @ hides the failure. Expected: the partial <tempDir>/<asset name> file is removed.

Steps to reproduce

  1. Point DLoad at a repository whose newest releases fail to download for the platform. For example, use a fake GitHub API where the asset URLs of the latest releases return an error.
  2. Set an isolated temp directory and run get.
  3. After the command fails, the temp directory contains one empty file per attempted release, e.g. roadrunner-3.4.0-linux-amd64.tar.gz, roadrunner-3.2.0-linux-amd64.tar.gz, roadrunner-3.1.0-linux-amd64.tar.gz.

Proposed solution

  • Unlink $file->getPathname().
  • Release the SplFileObject handle before unlinking. On Windows, unlink() on a file that is still open fails.

Additional context

  • Found while reviewing feat: use DLoad to download binaries roadrunner-php/cli#49, which moves rr get-binary to DLoad. The previous RoadRunner CLI downloader removed its temp file on failure.
  • The temp file name is the asset name, so two parallel downloads of the same asset write to the same file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions