Example #1
0
 public function updateFileList()
 {
     //$this->file_list=array();
     if ($this->verification != $GLOBALS['data']->verification['local']) {
         $file_list_copy = $this->file_list;
         foreach ($GLOBALS['data']->installed_packages as $packageName => $packageData) {
             if ($this->file_list[$packageName]) {
                 if ($this->file_list[$packageName]['version'] != $packageData['version']) {
                     // Update
                     $this->file_list[$packageName] = PacmanData::parsePacmanDataFile($GLOBALS['pacman_directory'] . 'local/' . $packageData['dir'] . '/files');
                     $packageFiles = $this->file_list[$packageName]['%FILES%'];
                     $files_count = count($packageFiles);
                     for ($i = 0; $i < $files_count; $i++) {
                         eval('$packageFiles[$i]="/' . str_replace(array('?', '$'), array('\\?', '\\$'), $packageFiles[$i]) . '";');
                     }
                     $this->file_list[$packageName]['%FILES%'] = $packageFiles;
                     $this->file_list[$packageName]['version'] = $packageData['version'];
                 }
             } else {
                 // Add
                 $this->file_list[$packageName] = PacmanData::parsePacmanDataFile($GLOBALS['pacman_directory'] . 'local/' . $packageData['dir'] . '/files');
                 $packageFiles = $this->file_list[$packageName]['%FILES%'];
                 $files_count = count($packageFiles);
                 for ($i = 0; $i < $files_count; $i++) {
                     eval('$packageFiles[$i]="/' . str_replace(array('?', '$'), array('\\?', '\\$'), $packageFiles[$i]) . '";');
                 }
                 $this->file_list[$packageName]['%FILES%'] = $packageFiles;
                 $this->file_list[$packageName]['version'] = $packageData['version'];
             }
             unset($file_list_copy[$packageName]);
         }
         if (count($file_list_copy)) {
             foreach ($file_list_copy as $packageName => $filesData) {
                 unset($this->file_list[$packageName]);
             }
         }
         $this->verification = $GLOBALS['data']->verification['local'];
         Std::write($GLOBALS['tupac_directory'] . '/tupac_filelist', serialize($this));
         chmod($GLOBALS['tupac_directory'] . '/tupac_filelist', 0666);
     }
 }
Example #2
0
function checkCache()
{
    // Check if we hgave cache
    if (!file_exists($GLOBALS['tupac_directory'] . '/tupac_data')) {
        // If any of the main files is missing, regenerate cache
        Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
        Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
        sendMessage('generatingCache', array());
        // Gather information
        $GLOBALS['data'] = new PacmanData();
        $GLOBALS['data']->updateList();
    } else {
        // Read Cache
        $GLOBALS['data'] = unserialize(getFileContents($GLOBALS['tupac_directory'] . '/tupac_data'));
        if ($GLOBALS['data'] === false) {
            // Unserialized failed
            sendMessage('generatingCacheCorrupted', array());
            Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
            Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
            $GLOBALS['data'] = new PacmanData();
            $GLOBALS['data']->updateList();
        } else {
            switch ($GLOBALS['data']->verifyIntegrity()) {
                case 'cache_updated':
                    sendMessage('generatingCacheTupacUpdated', array());
                    Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
                    Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
                    $GLOBALS['data'] = new PacmanData();
                    $GLOBALS['data']->updateList();
                    break;
                case 'database_outdated':
                    //sendMessage('generatingCacheDatabaseUpdated',array());
                    $anyChanges = false;
                    // Get currently available repos
                    $available_repos = array();
                    $dh = getRepoDirList();
                    foreach ($dh as $repo) {
                        if (!substr($repo, 0, 1) == '.' && is_dir(getRepoDir($repo))) {
                            $available_repos[$repo] = false;
                        }
                    }
                    // The database needs to be updated
                    $mustRecheckLocal = false;
                    $repo_list = $GLOBALS['data']->repo_list;
                    foreach ($repo_list as $repo => $repoData) {
                        unset($available_repos[$repo]);
                        if ($repo == 'local' && $GLOBALS['data']->verification[$repo] != PacmanData::verifyRepo($repo)) {
                            // We check local separately, since it is not a repo.
                            sendMessage('repoIsUpdated', array('%r' => $repo));
                            $anyChanges = true;
                            $installed = true;
                            $available_packages = array();
                            // get current packages
                            $dh = opendir(getRepoDir($repo));
                            while (FALSE !== ($package = readdir($dh))) {
                                if (substr($package, 0, 1) != '.' && is_dir(getRepoDir($repo) . $package)) {
                                    $packageName = preg_replace('/\\-[0-9a-z\\._A-Z]*\\-[0-9a-z\\._A-Z]*$/', '', $package);
                                    $available_packages[$packageName] = $package;
                                }
                            }
                            closedir($dh);
                            $installed_packages = $GLOBALS['data']->installed_packages;
                            // Walk packages of the current repo
                            foreach ($installed_packages as $packageName => $packageData) {
                                if (!$available_packages[$packageName]) {
                                    // The package is not installed anymore
                                    sendMessage('removePackage', array('%p' => $packageName));
                                    unset($repo_list['local'][$packageName]);
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = 'false';
                                        }
                                    }
                                    unset($installed_packages[$packageName]);
                                } elseif ($packageData['dir'] != $available_packages[$packageName]) {
                                    // Package updated. Since it is the list of installed packages, set its version to installed version
                                    sendMessage('updatePackage', array('%p' => $packageName));
                                    $installed_packages[$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], 'true');
                                    $installed_info = $installed_packages[$packageName]['version'];
                                    $installed_packages[$packageName]['installed'] = $installed_info;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = $installed_info;
                                            // in local installed version equals to avaiable version
                                            if ($repo == 'local') {
                                                $repo_list[$tmpRepo][$packageName]['version'] = $installed_info;
                                            }
                                        }
                                    }
                                }
                                unset($available_packages[$packageName]);
                            }
                            // Add new packages. This is, packages that are listed in the repo directory but that aren't marked as installed.
                            foreach ($available_packages as $packageName => $package) {
                                if ($package) {
                                    $packageFound = false;
                                    sendMessage('addPackage', array('%p' => $packageName));
                                    $installed_packages[$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], 'true');
                                    $installed_info = $installed_packages[$packageName]['version'];
                                    $installed_packages[$packageName]['installed'] = $installed_info;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = $installed_info;
                                            $packageFound = true;
                                        }
                                    }
                                    // It wasn't in any repo. Let's add it to the pseudorepo local
                                    if (!$packageFound) {
                                        $repo_list['local'][$packageName] = $installed_packages[$packageName];
                                    }
                                }
                            }
                            $GLOBALS['data']->installed_packages = $installed_packages;
                            $GLOBALS['data']->verification[$repo] = PacmanData::verifyRepo($repo);
                            continue;
                        }
                        if (!is_dir(getRepoDir($repo))) {
                            sendMessage('repoIsGone', array('%r' => $repo));
                            unset($repo_list[$repo]);
                            foreach ($repoData as $packageName => $packageData) {
                                if ($GLOBALS['data']->installed_packages[$packageName]) {
                                    $packageFound = false;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                            $packageFound = true;
                                            break;
                                        }
                                    }
                                    if (!$packageFound) {
                                        $repo_list['local'][$packageName] = $packageData;
                                    }
                                }
                            }
                            $anyChanges = true;
                        } else {
                            if ($GLOBALS['data']->verification[$repo] != PacmanData::verifyRepo($repo)) {
                                sendMessage('repoIsUpdated', array('%r' => $repo));
                                $anyChanges = true;
                                $available_packages = array();
                                // get current packages
                                $dh = opendir(getRepoDir($repo));
                                while (FALSE !== ($package = readdir($dh))) {
                                    if (substr($package, 0, 1) != '.' && is_dir(getRepoDir($repo) . $package)) {
                                        $packageName = preg_replace('/\\-[0-9a-z\\._A-Z]*\\-[0-9a-z\\._A-Z]*$/', '', $package);
                                        $available_packages[$packageName] = $package;
                                    }
                                }
                                closedir($dh);
                                // Walk packages of the current repo
                                foreach ($repoData as $packageName => $packageData) {
                                    if (!$available_packages[$packageName]) {
                                        // The package doesn't exist anymore in the directory of the repo
                                        sendMessage('removePackage', array('%p' => $packageName));
                                        if ($packageData['installed'] != 'false') {
                                            // since it is installed, we have to move it to the pseudorepo local
                                            $repo_list['local'][$packageName] = $repo_list[$repo][$packageName];
                                            $packageFound = false;
                                            foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                                if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                                    $packageFound = true;
                                                }
                                            }
                                            if (!$packageFound) {
                                                $repo_list['local'][$packageName] = $packageData;
                                            }
                                        }
                                        unset($repo_list[$repo][$packageName]);
                                    } elseif ($packageData['dir'] != $available_packages[$packageName]) {
                                        // Package updated
                                        sendMessage('updatePackage', array('%p' => $packageName));
                                        $installed_info = $packageData['installed'];
                                        $repo_list[$repo][$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], $installed_info);
                                    }
                                    unset($available_packages[$packageName]);
                                }
                                // Add new packages. This is, packages that are listed in the repo directory but that aren't available in the repo.
                                foreach ($available_packages as $packageName => $package) {
                                    if ($package) {
                                        sendMessage('addPackage', array('%p' => $packageName));
                                        $repo_list[$repo][$packageName] = PacmanData::getPackageData($repo, $package, $installed);
                                        // Add install information
                                        if ($repo_list['local'][$packageName]) {
                                            $GLOBALS['data']->installed_packages[$packageName] = $repo_list['local'][$packageName];
                                        }
                                        if ($GLOBALS['data']->installed_packages[$packageName]) {
                                            unset($repo_list['local'][$packageName]);
                                            $repo_list[$repo][$packageName]['installed'] = $GLOBALS['data']->installed_packages[$packageName]['version'];
                                            // remove it from the pseudo repo local
                                            if ($repo_list['local'][$packageName]) {
                                                unset($repo_list['local'][$packageName]);
                                            }
                                        } else {
                                            $repo_list[$repo][$packageName]['installed'] = 'false';
                                        }
                                    }
                                }
                                $GLOBALS['data']->verification[$repo] = PacmanData::verifyRepo($repo);
                            }
                        }
                    }
                    $GLOBALS['data']->repo_list = $repo_list;
                    foreach ($available_repos as $repo => $dummy) {
                        sendMessage('repoIsNew', array('%r' => $repo));
                        $GLOBALS['data']->getRepoData($repo);
                        $mustRecheckLocal = true;
                    }
                    if ($mustRecheckLocal) {
                        $anyChanges = true;
                        sendMessage('recheckingLocal', array());
                        // we copy installed packages to pseudorepo local
                        $GLOBALS['data']->repo_list['local'] = array_merge($GLOBALS['data']->installed_packages, $GLOBALS['data']->repo_list['local']);
                        $GLOBALS['data']->recheckLocal();
                    }
                    if ($anyChanges) {
                        sendMessage('saving', array());
                        $GLOBALS['data']->saveData();
                    }
                    break;
                default:
                    // We never get here
                    //sendMessage('reusingCache',array());
                    break;
            }
        }
    }
}
Example #3
0
File: tupac.php Project: Kett/tupac
     }
     break;
 case '-Ss':
     checkCache();
     $GLOBALS['NO_PROMP'] = true;
     $parms = $argv;
     array_splice($parms, 0, 2);
     $GLOBALS['data']->searchByPackageNameAndDescription($parms);
     break;
 case '--checkdir':
     checkCache();
     $GLOBALS['data']->checkDirectory($argv[2]);
     break;
 case '--orphans':
     checkCache();
     PacmanData::findUnownedFiles($argv[2]);
     break;
 case '--console':
     checkCache();
     echo "u: update cache\n";
     echo "s [word] [word] ...: search words omiting aur\n";
     echo "sa [word] [word] ...: search words including aur\n";
     echo "sp [word] [word] ...: search words omiting aur. prompt what to install\n";
     echo "spa [word] [word] ...: search words including aur. prompt what to install\n";
     echo "i [number] [number] ...: isntall result numbers from last search\n";
     echo "exit: exit console\n";
     while (true) {
         $input = split(' ', trim(readline('$ ')));
         switch ($input[0]) {
             case 'u':
                 checkCache();
Example #4
0
 static function findUnownedFiles($dir)
 {
     $dir = str_replace('./', '', $dir);
     if (!preg_match('/^\\//', $dir)) {
         $dir = getcwd() . '/' . $dir;
     }
     if (!is_dir($dir)) {
         return sendMessage('invalidDirectory', array('%dir' => $dir));
     }
     PacmanData::initializeFileList();
     walkDir($dir);
     $dir_strlen = strlen($dir);
     $progress_position = 0;
     $progress_length = count($GLOBALS['pacman_file_list']->file_list);
     foreach ($GLOBALS['pacman_file_list']->file_list as $packageName => $packageData) {
         echo "\r" . round($progress_position++ / $progress_length * 10000) / 100 . '%';
         $tmpFiles = $packageData['%FILES%'];
         $tmpFiles_count = count($tmpFiles);
         for ($i = 0; $i < $tmpFiles_count; $i++) {
             $currFile = $tmpFiles[$i];
             $GLOBALS['WALK_DIR_RESULTS'][$currFile] = FALSE;
         }
     }
     echo "\r";
     foreach ($GLOBALS['WALK_DIR_RESULTS'] as $file => $ownerMissing) {
         if ($ownerMissing === TRUE) {
             echo $file . "\n";
         }
     }
     if ($GLOBALS['uid'] != 0) {
         sendMessage('recomendRootOrphans', array());
     }
 }