From 604156950c42af1f0b592c6dc6758d44670db4da Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Thu, 12 Jun 2008 02:28:13 +0800 Subject: Make use of PEAR packages in pkgsubmit.php Uses File_Find and Archive_Tar in pkgsubmit.php Removes references to PackageContents Signed-off-by: Callan Barrett --- web/README.txt | 7 +- web/html/packages.php | 16 ++--- web/html/pkgsubmit.php | 172 +++++++++++++++++-------------------------------- 3 files changed, 72 insertions(+), 123 deletions(-) diff --git a/web/README.txt b/web/README.txt index 35c54e84..b9e54fb2 100644 --- a/web/README.txt +++ b/web/README.txt @@ -28,11 +28,16 @@ Setup on Arch Linux: 4) Configure PHP - Make sure you have mysql and json enabled in PHP + Make sure you have mysql and json enabled in PHP and + PEAR is properly configured - Edit php.ini and uncomment/add these lines: extension=mysql.so extension=json.so + + Install the File_Find PEAR package: + http://pear.php.net/package/File_Find + 5) Clone the AUR project (using the MYUSER from above) $ cd diff --git a/web/html/packages.php b/web/html/packages.php index 80ddf209..afee32e8 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -228,31 +228,27 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { # These are the packages that are safe to delete # foreach ($ids_to_delete as $id) { - # 1) delete from PackageVotes + # delete from PackageVotes $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; $result = db_query($q, $dbh); - # 2) delete from PackageContents - $q = "DELETE FROM PackageContents WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # 3) delete from PackageDepends + # delete from PackageDepends $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; $result = db_query($q, $dbh); - # 4) delete from PackageSources + # delete from PackageSources $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; $result = db_query($q, $dbh); - # 5) delete from PackageComments + # delete from PackageComments $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; $result = db_query($q, $dbh); - # 6) delete from Packages + # delete from Packages $q = "DELETE FROM Packages WHERE ID = " . $id; $result = db_query($q, $dbh); - # 7) delete from CommentNotify + # delete from CommentNotify $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; $result = db_query($q, $dbh); diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 00ac8617..23fae2cf 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -1,48 +1,60 @@ \n"; -echo "
".__("Submit")."
\n"; -echo "
\n"; +html_header("Submit"); + +?> + +
+
+ +
+
+ +extract(); + + if (!$extract) { $error = __("Unknown file format for uploaded file."); } } @@ -50,67 +62,21 @@ if ($_COOKIE["AURSID"]) { } } - # where is the pkgbuild?! + # Find the PKGBUILD if (!$error) { - $d = dir(UPLOAD_DIR . $tempdir); - - $pkgbuild = ""; - $deepdir = ""; - while ($file = $d->read()) { - # try to find a PKGBUILD in the top level (naughty! :O) and - # also the first directory found to use for the next part if required - if ($file == "PKGBUILD") { - $pkgbuild = UPLOAD_DIR . $tempdir . "/PKGBUILD"; - $pkg_dir = UPLOAD_DIR . $tempdir; - break; - } else if (is_dir($file)) { - # we'll assume the first directory we find is the one with - # the pkgbuild in it - if ($file != "." && $file != "..") { - $deepdir = $file; - break; - } - } - } - - # if we couldn't find a pkgbuild in the top level we'll - # check in the first dir we found, if it's not there we assume - # there isn't any (even if there was the user should upload a proper tarball) - if ($pkgbuild == "" && $deepdir != "") { - $d = dir(UPLOAD_DIR . $tempdir . "/" . $deepdir); - while ($file = $d->read()) { - if ($file == "PKGBUILD") { - # oh my - $pkgbuild = UPLOAD_DIR . $tempdir . "/" . $deepdir ."/PKGBUILD"; - $pkg_dir = UPLOAD_DIR . $tempdir . "/" . $deepdir; - break; - } - } - if ($pkgbuild == "") { - $error = __("Error trying to unpack upload - PKGBUILD does not exist."); - } - } - - # we know where our pkgbuild is now, woot woot + $pkgbuild = File_Find::search('PKGBUILD', $tempdir); + + if (count($pkgbuild) > 0) { + $pkgbuild = $pkgbuild[0]; + $pkg_dir = dirname($pkgbuild); + } else { + $error = __("Error trying to unpack upload - PKGBUILD does not exist."); + } } # if no error, get list of directory contents and process PKGBUILD # if (!$error) { - # get list of files - # - $d = dir($pkg_dir); - $pkg_contents = array(); - while ($f = $d->read()) { - if ($f != "." && $f != "..") { - $pkg_contents[$f] = filesize($pkg_dir . "/" . $f); - if (preg_match("/^(.*\.pkg\.tar\.gz|filelist)$/", $f)) { - $error = __("Binary packages and filelists are not allowed for upload."); - } - } - } - $d->close(); - # process PKGBIULD - remove line concatenation # $pkgbuild = array(); @@ -252,10 +218,10 @@ if ($_COOKIE["AURSID"]) { $pkgver_var = $pkgbuild["pkgver"]; $new_pkgbuild = array(); while (list($k, $v) = each($pkgbuild)) { - $v = str_replace("\$pkgname", $pkgname_var, $v); - $v = str_replace("\${pkgname}", $pkgname_var, $v); - $v = str_replace("\$pkgver", $pkgver_var, $v); - $v = str_replace("\${pkgver}", $pkgver_var, $v); + $v = str_replace('$pkgname', $pkgname_var, $v); + $v = str_replace('${pkgname}', $pkgname_var, $v); + $v = str_replace('$pkgver', $pkgver_var, $v); + $v = str_replace('${pkgver}', $pkgver_var, $v); $new_pkgbuild[$k] = $v; } } @@ -295,8 +261,7 @@ if ($_COOKIE["AURSID"]) { array(INCOMING_DIR.$pkg_name)); } - $shcmd = "/bin/mv " . $pkg_dir . " " . escapeshellarg(INCOMING_DIR . $pkg_name . "/" . $pkg_name); - @exec($shcmd); + rename($pkg_dir, INCOMING_DIR . $pkg_name . "/" . $pkg_name); } else { $error = __("You are not allowed to overwrite the %h%s%h package.", array("", $pkg_name, "")); @@ -313,15 +278,17 @@ if ($_COOKIE["AURSID"]) { } if (!$error) { - @exec("/bin/sh -c 'tar czf ".$pkg_name.".tar.gz ".$pkg_name."'", $trash, $retval); - if ($retval) { + $tar = new Archive_Tar($pkg_name . '.tar.gz'); + $create = $tar->create(array($pkg_name)); + + if (!$create) { $error = __("Could not re-tar"); } } # whether it failed or not we can clean this out - if (file_exists(UPLOAD_DIR . $tempdir)) { - rm_rf(UPLOAD_DIR . $tempdir); + if (file_exists($tempdir)) { + rm_rf($tempdir); } # update the backend database @@ -342,8 +309,6 @@ if ($_COOKIE["AURSID"]) { # flush out old data that will be replaced with new data # - $q = "DELETE FROM PackageContents WHERE PackageID = ".$pdata["ID"]; - db_query($q, $dbh); $q = "DELETE FROM PackageDepends WHERE PackageID = ".$pdata["ID"]; db_query($q, $dbh); $q = "DELETE FROM PackageSources WHERE PackageID = ".$pdata["ID"]; @@ -380,18 +345,6 @@ if ($_COOKIE["AURSID"]) { $q.="WHERE ID = " . $pdata["ID"]; $result = db_query($q, $dbh); - # update package contents - # - while (list($k, $v) = each($pkg_contents)) { - $q = "INSERT INTO PackageContents "; - $q.= "(PackageID, FSPath, URLPath, FileSize) VALUES ("; - $q.= $pdata['ID'].", "; - $q.= "'".INCOMING_DIR.$pkg_name."/".$pkg_name."/".$k."', "; - $q.= "'".URL_DIR.$pkg_name."/".$pkg_name."/".$k."', "; - $q.= $v.")"; - db_query($q); - } - # update package depends # $depends = explode(" ", $new_pkgbuild['depends']); @@ -453,18 +406,6 @@ if ($_COOKIE["AURSID"]) { $packageID = mysql_insert_id($dbh); - # update package contents - # - while (list($k, $v) = each($pkg_contents)) { - $q = "INSERT INTO PackageContents "; - $q.= "(PackageID, FSPath, URLPath, FileSize) VALUES ("; - $q.= $packageID.", "; - $q.= "'".INCOMING_DIR.$pkg_name."/".$pkg_name."/".$k."', "; - $q.= "'".URL_DIR.$pkg_name."/".$pkg_name."/".$k."', "; - $q.= $v.")"; - db_query($q); - } - # update package depends # $depends = explode(" ", $new_pkgbuild['depends']); @@ -579,8 +520,15 @@ if ($_COOKIE["AURSID"]) { print __("You must create an account before you can upload packages."); print "
\n"; } -echo "
\n"; -echo "
\n"; + +?> + +
+ + + -- cgit v1.2.3-24-g4f1b