1
0
Fork 0

Add temporary metadata for download size tracking

pull/10249/head
Jordi Boggiano 2021-10-29 22:19:03 +02:00
parent 96370657b8
commit 3f243d37c3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 19 additions and 1 deletions

View File

@ -57,6 +57,13 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
protected $eventDispatcher;
/** @var ProcessExecutor */
protected $process;
/**
* @var array<string, int|string>
* @private
* @internal
*/
public static $downloadMetadata = array();
/**
* @private this is only public for php 5.3 support in closures
*
@ -218,6 +225,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$accept = function ($response) use ($cache, $package, $fileName, $self, &$urls) {
$url = reset($urls);
$cacheKey = $url['cacheKey'];
FileDownloader::$downloadMetadata[$package->getName()] = @filesize($fileName) ?: $response->getHeader('Content-Length') ?: '?';
if ($cache && !$cache->isReadOnly()) {
$self->lastCacheWrites[$package->getName()] = $cacheKey;

View File

@ -23,6 +23,7 @@ use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use Composer\Downloader\FileDownloader;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Loop;
use Composer\Util\Platform;
@ -65,6 +66,7 @@ class InstallationManager
public function reset()
{
$this->notifiablePackages = array();
FileDownloader::$downloadMetadata = array();
}
/**
@ -662,10 +664,18 @@ class InstallationManager
$postData = array('downloads' => array());
foreach ($packages as $package) {
$postData['downloads'][] = array(
$packageNotification = array(
'name' => $package->getPrettyName(),
'version' => $package->getVersion(),
);
if (strpos($repoUrl, 'packagist.org/') !== false) {
if (isset(FileDownloader::$downloadMetadata[$package->getName()])) {
$packageNotification['downloaded'] = FileDownloader::$downloadMetadata[$package->getName()];
} else {
$packageNotification['downloaded'] = false;
}
}
$postData['downloads'][] = $packageNotification;
}
$opts = array(