/**
  * Backs up the paths.
  */
 public function preserve()
 {
     foreach ($this->installPaths as $installPath) {
         $installPathNormalized = $this->filesystem->normalizePath($installPath);
         // Check if any path may be affected by modifying the install path.
         $relevant_paths = array();
         foreach ($this->preservePaths as $path) {
             $normalizedPath = $this->filesystem->normalizePath($path);
             if (static::file_exists($path) && strpos($normalizedPath, $installPathNormalized) === 0) {
                 $relevant_paths[] = $normalizedPath;
             }
         }
         // If no paths need to be backed up, we simply proceed.
         if (empty($relevant_paths)) {
             continue;
         }
         $unique = $installPath . ' ' . time();
         $cache_root = $this->filesystem->normalizePath($this->cacheDir . '/preserve-paths/' . sha1($unique));
         $this->filesystem->ensureDirectoryExists($cache_root);
         // Before we back paths up, we need to make sure, permissions are
         // sufficient to that task.
         $this->preparePathPermissions($relevant_paths);
         foreach ($relevant_paths as $original) {
             $backup_location = $cache_root . '/' . sha1($original);
             $this->filesystem->rename($original, $backup_location);
             $this->backups[$original] = $backup_location;
         }
     }
 }
 /**
  * Remove the paths.
  */
 public function remove()
 {
     foreach ($this->installPaths as $installPath) {
         $installPathNormalized = $this->filesystem->normalizePath($installPath);
         // Check if any path may be affected by modifying the install path.
         $relevant_paths = array();
         foreach ($this->removePaths as $path) {
             $normalizedPath = $this->filesystem->normalizePath($path);
             if (static::file_exists($path) && strpos($normalizedPath, $installPathNormalized) === 0) {
                 $relevant_paths[] = $normalizedPath;
             }
         }
         foreach ($relevant_paths as $original) {
             if (is_dir($original)) {
                 // Remove directory
                 $this->removeDirectoryRecursively($original);
             } else {
                 // Remove file
                 unlink($original);
             }
         }
     }
 }