/**
  * Restore previously backed up paths.
  *
  * @see PathPreserver::backupSubpaths()
  */
 public function rollback()
 {
     if (empty($this->backups)) {
         return;
     }
     foreach ($this->backups as $original => $backup_location) {
         // Remove any code that was placed by the package at the place of
         // the original path.
         if (static::file_exists($original)) {
             if (is_dir($original)) {
                 $this->filesystem->emptyDirectory($original, false);
                 $this->filesystem->removeDirectory($original);
             } else {
                 $this->filesystem->remove($original);
             }
             $this->io->write(sprintf('<comment>Files of installed package were overwritten with preserved path %s!</comment>', $original), true);
         }
         $folder = dirname($original);
         $this->filesystem->ensureDirectoryExists($folder);
         // Make sure we can write the file to the folder.
         $this->makePathWritable($folder);
         $this->filesystem->rename($backup_location, $original);
         if ($this->filesystem->isDirEmpty(dirname($backup_location))) {
             $this->filesystem->removeDirectory(dirname($backup_location));
         }
     }
     // Restore all path permissions, that where set for the sake of moving
     // things around.
     $this->restorePathPermissions();
     // With a clean array, we can start over.
     $this->backups = array();
 }
 protected function afterDrupalRemoveGitDir(PackageEvent $event, IOInterface $io, PackageInterface $package)
 {
     $packagePath = $this->installer->getPackageBasePath($package);
     $gitPath = "{$packagePath}/.git";
     $file = new FileSystem();
     $file->removeDirectory($gitPath);
     $io->write("<info>Removed {$packagePath}/.git</info>");
 }
 protected function afterDrupalGitBackup(PackageEvent $event, PackageInterface $package)
 {
     if (!$this->git['path']) {
         return;
     }
     $packagePath = $this->installer->getPackageBasePath($package);
     $gitPath = "{$packagePath}/.git";
     $backupPath = $packagePath . '/' . $this->git['path'];
     if (file_exists($gitPath)) {
         $this->io->write("  - Moving <info>{$gitPath}</info> to <info>{$backupPath}</info>.");
         $file = new FileSystem();
         $file->removeDirectory($backupPath);
         $file->rename($gitPath, $backupPath);
     }
 }