function isSubpackageOf(\Pyrus\PackageFileInterface $p) { return $p->isSubpackage($this); }
/** * Detect any files already installed that would be overwritten by * files inside the package represented by $package */ public function detectFileConflicts(\Pyrus\PackageFileInterface $package) { // construct list of all installed files $filesByPackage = $allfiles = array(); $config = \Pyrus\Config::current(); foreach ($config->channelregistry as $channel) { foreach ($this->listPackages($channel->name) as $packagename) { $files = $this->info($packagename, $channel->name, 'installedfiles'); $newfiles = array(); foreach ($files as $file) { $newfiles[$file['installed_as']] = $file; } $filesByPackage[$channel->name . '/' . $packagename] = $newfiles; $allfiles = array_merge($allfiles, $newfiles); } } // now iterate over each file in the package, and note all the conflicts $roles = array(); foreach (Role::getValidRoles($package->getPackageType()) as $role) { // set up a list of file role => configuration variable // for storing in the registry $roles[$role] = Role::factory($package->getPackageType(), $role); } $ret = array(); foreach ($package->installcontents as $file) { $relativepath = $roles[$file->role]->getRelativeLocation($package, $file); if (!$relativepath) { continue; } $testpath = $config->{$roles[$file->role]->getLocationConfig()} . DIRECTORY_SEPARATOR . $relativepath; if (isset($allfiles[$testpath])) { foreach ($filesByPackage as $pname => $files) { if (isset($files[$testpath])) { $ret[] = array($relativepath => $pname); break; } } } } return $ret; }
/** * Detect any files already installed that would be overwritten by * files inside the package represented by $package */ public function detectFileConflicts(\Pyrus\PackageFileInterface $package) { if (!static::existsRegistry($this->_path)) { throw new \Pyrus\ChannelRegistry\Exception('Error: no existing SQLite3 channel registry for ' . $this->_path); } $database = static::getRegistry($this->_path); $ret = array(); $sql = 'SELECT packages_channel, packages_name FROM files WHERE packagepath = :path ORDER BY packages_channel, packages_name'; $stmt = $database->prepare($sql); // now iterate over each file in the package, and note all the conflicts $roles = array(); foreach (Role::getValidRoles($package->getPackageType()) as $role) { // set up a list of file role => configuration variable // for storing in the registry $roles[$role] = Role::factory($package->getPackageType(), $role); } $ret = array(); $config = Config::current(); foreach ($package->installcontents as $file) { $stmt->reset(); $relativepath = $roles[$file->role]->getRelativeLocation($package, $file); if (!$relativepath) { continue; } $testpath = $config->{$roles[$file->role]->getLocationConfig()} . DIRECTORY_SEPARATOR . $relativepath; $stmt->bindValue(':path', $testpath, SQLITE3_TEXT); $result = $stmt->execute(); while ($res = $result->fetchArray(SQLITE3_ASSOC)) { $pn = $this->info($res['packages_name'], $res['packages_channel'], 'name'); $ret[] = array($relativepath => $res['packages_channel'] . '/' . $pn); } } return $ret; }
function getRelativeLocation(\Pyrus\PackageFileInterface $pkg, \Pyrus\PackageFile\v2Iterator\FileTag $file, $retDir = false) { if (!$this->info['locationconfig']) { return false; } if ($this->info['honorsbaseinstall']) { $dest_dir = ''; if ($file->baseinstalldir) { $dest_dir .= $file->baseinstalldir; } } elseif ($this->info['unusualbaseinstall']) { if (!$pkg->isNewPackage()) { // Place files using the old doc dir structure $dest_dir = $pkg->name; } else { $dest_dir = $pkg->channel . DIRECTORY_SEPARATOR . $pkg->name; } if ($file->baseinstalldir) { $dest_dir .= DIRECTORY_SEPARATOR . $file->baseinstalldir; } } else { $dest_dir = $pkg->channel . DIRECTORY_SEPARATOR . $pkg->name; } if (dirname($file->name) != '.' && empty($file['install-as'])) { $newpath = dirname($file->name); if ($pkg->isNewPackage()) { // strip role from file path // so php/Path/To/File.php becomes Path/To/File.php, // data/package.xsd becomes package.xsd $r = get_class($this); $r = strtolower(substr($r, strrpos($r, '\\') + 1)); if ($r === 'php') { if (strpos($newpath, 'src') === 0) { $newpath = substr($newpath, 4); if ($newpath === false) { $newpath = ''; } } } if (strpos($newpath, $r) === 0) { $newpath = substr($newpath, strlen($r) + 1); if ($newpath === false) { $newpath = ''; } } $r = $pkg->channel . DIRECTORY_SEPARATOR . $pkg->name; if (strpos($newpath, $r) === 0) { // Trim off extra channel and package name directories $newpath = substr($newpath, strlen($r) + 1); if ($newpath === false) { $newpath = ''; } } } if ($dest_dir && $newpath) { $dest_dir .= DIRECTORY_SEPARATOR; } $dest_dir .= $newpath; } if ($dest_dir) { $dest_dir .= DIRECTORY_SEPARATOR; } $dest_file = $dest_dir; if (empty($file['install-as'])) { $dest_file .= basename($file->name); } else { $dest_file .= $file['install-as']; } if ($retDir) { // Clean up the DIRECTORY_SEPARATOR mess $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; list($dest_dir, $dest_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array($dest_dir, $dest_file)); if ($dest_file[0] == DIRECTORY_SEPARATOR) { $dest_file = substr($dest_file, 1); } return array($dest_dir, $dest_file); } // Clean up the DIRECTORY_SEPARATOR mess $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; $dest_file = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $dest_file); if ($dest_file[0] == DIRECTORY_SEPARATOR) { $dest_file = substr($dest_file, 1); } return $dest_file; }
/** * Detect any files already installed that would be overwritten by * files inside the package represented by $package */ public function detectFileConflicts(\Pyrus\PackageFileInterface $package) { $filemap = $this->readFileMap(); if (!$filemap) { return array(); } // now iterate over each file in the package, and note all the conflicts $roles = array(); foreach (Role::getValidRoles($package->getPackageType()) as $role) { // set up a list of file role => configuration variable // for storing in the registry $roles[$role] = Role::factory($package->getPackageType(), $role); } $ret = array(); foreach ($package->installcontents as $file) { $relativepath = $roles[$file->role]->getRelativeLocation($package, $file); if (!$relativepath) { continue; } if (isset($filemap[$file->role][$relativepath])) { if (is_array($filemap[$file->role][$relativepath])) { $ret[] = array($relativepath => $filemap[$file->role][$relativepath][0] . '/' . $this->info($filemap[$file->role][$relativepath][1], $filemap[$file->role][$relativepath][0], 'name')); } else { $ret[] = array($relativepath => 'pear.php.net/' . $this->info($filemap[$file->role][$relativepath], 'pear.php.net', 'name')); } } } return $ret; }