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

Fix package cleanup #14

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## Unreleased

### Added

- Checking for the type of package before cleanup. Not clean packages with the `metapackage` type

## v2.6.0

### Changed
Expand Down
22 changes: 22 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class Plugin implements PluginInterface, EventSubscriberInterface
{
public const SELF_PACKAGE_NAME = 'avto-dev/composer-cleanup-plugin';

private const PACKAGE_TYPE_METAPACKAGE = 'metapackage';

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -80,6 +82,10 @@ public static function cleanupAllPackages(ScriptEvent $event): void

// Loop over all installed packages
foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
if (self::isMetapackage($package)) {
continue;
}

$package_name = $package->getName();
$install_path = $installation_manager->getInstallPath($package) ?: '';

Expand Down Expand Up @@ -136,6 +142,10 @@ public static function handlePostPackageUpdateEvent(PackageEvent $event): void
*/
protected static function cleanupPackage(PackageInterface $package, IOInterface $io, Composer $composer): void
{
if (self::isMetapackage($package)) {
return;
}

$fs = new Filesystem;
$saved_size_bytes = 0;
$package_rules = Rules::getPackageRules();
Expand Down Expand Up @@ -189,4 +199,16 @@ private static function makeClean(string $package_path, array $rules, Filesystem

return $saved_size_bytes;
}

/**
* Metapackage is an empty package that contains requirements and will trigger their installation,
* but contains no files and will not write anything to the filesystem.
*
* @param PackageInterface $package
* @return bool
*/
private static function isMetapackage(PackageInterface $package): bool
{
return self::PACKAGE_TYPE_METAPACKAGE === $package->getType();
}
}