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/html/pkgsubmit.php | 172 +++++++++++++++++-------------------------------- 1 file changed, 60 insertions(+), 112 deletions(-) (limited to 'web/html/pkgsubmit.php') 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