<commit_before><?php
namespace Aura\Composer;

use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;

class SystemInstaller extends LibraryInstaller
{
    /**
     * {@inheritDoc}
     */
    public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        // do the installation
        parent::install($repo, $package);
        list($vendor, $name) = $this->getVendorAndName($package);
        $new = "{$vendor}.{$name}";
        
        // is the package already listed?
        $packages = $this->readConfigPackages();
        foreach ($packages as $old) {
            if ($old == $new) {
                // already listed, so we're done
                return;
            }
        }
        
        // package was not listed; append to the list and write to disk
        $packages[] = $new;
        $this->writeConfigPackages($packages);
    }
    
    /**
     * {@inheritDoc}
     */
    public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        // do the installation
        parent::uninstall($repo, $package);
        list($vendor, $name) = $this->getVendorAndName($package);
        
        // remove the package from the file listing
        $packages = $this->readConfigPackages();
        foreach ($packages as $key => $val) {
            if ($val == "{$vendor}.{$name}") {
                unset($packages[$key]);
                break;
            }
        }
        
        // write the list back to disk
        $this->writeConfigPackages($packages);
    }
    
    /**
     * {@inheritDoc}
     */
    public function getInstallPath(PackageInterface $package)
    {
        list($vendor, $name) = $this->getVendorAndName($package);
        return "package/{$vendor}.{$name}";
    }

    /**
     * {@inheritDoc}
     */
    public function supports($packageType)
    {
        return $packageType == 'aura-package';
    }
    
    /**
     * 
     * Returns the path to the "config/_packages" file.
     * 
     * @return string
     * 
     */
    private function getConfigPackagesFile()
    {
        // system/vendor/aura/installer-system/src/Aura/Composer/SystemInstaller.php
        $root = dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))));
        $file = $root . DIRECTORY_SEPARATOR
              . 'config' . DIRECTORY_SEPARATOR
              . '_packages';
        if (! file_exists($file)) {
            touch($file);
        }
        return $file;
    }
    
    /**
     * 
     * Reads the "config/_packages" file.
     * 
     * @return array An array of packages named in the file.
     * <commit_msg>remove one level of dirname()<commit_after><?php
namespace Aura\Composer;

use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;

class SystemInstaller extends LibraryInstaller
{
    /**
     * {@inheritDoc}
     */
    public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        // do the installation
        parent::install($repo, $package);
        list($vendor, $name) = $this->getVendorAndName($package);
        $new = "{$vendor}.{$name}";
        
        // is the package already listed?
        $packages = $this->readConfigPackages();
        foreach ($packages as $old) {
            if ($old == $new) {
                // already listed, so we're done
                return;
            }
        }
        
        // package was not listed; append to the list and write to disk
        $packages[] = $new;
        $this->writeConfigPackages($packages);
    }
    
    /**
     * {@inheritDoc}
     */
    public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        // do the installation
        parent::uninstall($repo, $package);
        list($vendor, $name) = $this->getVendorAndName($package);
        
        // remove the package from the file listing
        $packages = $this->readConfigPackages();
        foreach ($packages as $key => $val) {
            if ($val == "{$vendor}.{$name}") {
                unset($packages[$key]);
                break;
            }
        }
        
        // write the list back to disk
        $this->writeConfigPackages($packages);
    }
    
    /**
     * {@inheritDoc}
     */
    public function getInstallPath(PackageInterface $package)
    {
        list($vendor, $name) = $this->getVendorAndName($package);
        return "package/{$vendor}.{$name}";
    }

    /**
     * {@inheritDoc}
     */
    public function supports($packageType)
    {
        return $packageType == 'aura-package';
    }
    
    /**
     * 
     * Returns the path to the "config/_packages" file.
     * 
     * @return string
     * 
     */
    private function getConfigPackagesFile()
    {
        // system/vendor/aura/installer-system/src/Aura/Composer/SystemInstaller.php
        $root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
        $file = $root . DIRECTORY_SEPARATOR
              . 'config' . DIRECTORY_SEPARATOR
              . '_packages';
        if (! file_exists($file)) {
            touch($file);
        }
        return $file;
    }
    
    /**
     * 
     * Reads the "config/_packages" file.
     * 
     * @return array An array of packages named in the file.
     * 
{'fraction_non_alphanumeric': 0.128594980765708, 'fraction_numerical': 0.0, 'mean_word_length': 1.940226171243942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506919', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1493, 'n_words': 330}