Commit 556de318 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Build URLs from package names (fixes FS#15308, FS#19327).



Drop the "URLPath" field from the "Packages" table, build URLs from
package names instead.
Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent 0bb2a7b5
...@@ -9,7 +9,7 @@ From 1.7.0 to 1.8.0 ...@@ -9,7 +9,7 @@ From 1.7.0 to 1.8.0
---- ----
ALTER TABLE Packages ADD OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL; ALTER TABLE Packages ADD OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL;
UPDATE Packages SET OutOfDateTS = UNIX_TIMESTAMP() WHERE OutOfDate = 1; UPDATE Packages SET OutOfDateTS = UNIX_TIMESTAMP() WHERE OutOfDate = 1;
ALTER TABLE Packages DROP OutOfDate; ALTER TABLE Packages DROP OutOfDate, DROP URLPath;
---- ----
2. You will need to update all packages which are stored in the incoming dir as 2. You will need to update all packages which are stored in the incoming dir as
......
...@@ -115,7 +115,6 @@ CREATE TABLE Packages ( ...@@ -115,7 +115,6 @@ CREATE TABLE Packages (
URL CHAR(255) NOT NULL DEFAULT "http://www.archlinux.org", URL CHAR(255) NOT NULL DEFAULT "http://www.archlinux.org",
DummyPkg TINYINT UNSIGNED NOT NULL DEFAULT 0, -- 1=>dummy DummyPkg TINYINT UNSIGNED NOT NULL DEFAULT 0, -- 1=>dummy
FSPath CHAR(255) NOT NULL DEFAULT '', FSPath CHAR(255) NOT NULL DEFAULT '',
URLPath CHAR(255) NOT NULL DEFAULT '',
License CHAR(40) NOT NULL DEFAULT '', License CHAR(40) NOT NULL DEFAULT '',
LocationID TINYINT UNSIGNED NOT NULL DEFAULT 1, LocationID TINYINT UNSIGNED NOT NULL DEFAULT 1,
NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0, NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0,
......
...@@ -267,36 +267,30 @@ for p in seen_pkgs.keys(): ...@@ -267,36 +267,30 @@ for p in seen_pkgs.keys():
if location_id == 1: # Unsupported - just a PKGBUILD and maybe other stuff if location_id == 1: # Unsupported - just a PKGBUILD and maybe other stuff
others = random.randrange(0,3) others = random.randrange(0,3)
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "PKGBUILD", "/home/aur/incoming/%s/PKGBUILD" % p, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/PKGBUILD" % p,
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
if others == 0: if others == 0:
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "%s.patch" % p, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/%s.patch" % (p,p),
"/home/aur/incoming/%s/%s.patch" % (p,p),
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
elif others == 1: elif others == 1:
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "%s.patch" % p, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/%s.patch" % (p,p),
"/home/aur/incoming/%s/%s.patch" % (p,p),
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "arch.patch", s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/arch.patch" % p,
"/home/aur/incoming/%s/arch.patch" % p,
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
elif others == 2: elif others == 2:
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "%s.patch" % p, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/%s.patch" % (p,p),
"/home/aur/incoming/%s/%s.patch" % (p,p),
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "arch.patch", s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/arch.patch" % p,
"/home/aur/incoming/%s/arch.patch" % p,
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], "%s.install" % p, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], "/home/aur/incoming/%s/%s.install" % (p,p),
"/home/aur/incoming/%s/%s.install" % (p,p),
random.randrange(0,999)) random.randrange(0,999))
out.write(s) out.write(s)
...@@ -325,7 +319,7 @@ for p in seen_pkgs.keys(): ...@@ -325,7 +319,7 @@ for p in seen_pkgs.keys():
path = loc + "/" + p path = loc + "/" + p
if not files.has_key(path): if not files.has_key(path):
files[path] = 1 files[path] = 1
s = "INSERT INTO PackageContents (PackageID, URLPath, FSPath, FileSize) VALUES (%d, '%s', '%s', %d);\n" % (seen_pkgs[p], os.path.basename(path), path, s = "INSERT INTO PackageContents (PackageID, FSPath, FileSize) VALUES (%d, '%s', %d);\n" % (seen_pkgs[p], path,
random.randrange(0,99999999)) random.randrange(0,99999999))
out.write(s) out.write(s)
if DBUG: print "." if DBUG: print "."
......
...@@ -277,7 +277,7 @@ if ($_COOKIE["AURSID"]): ...@@ -277,7 +277,7 @@ if ($_COOKIE["AURSID"]):
} }
# Update package data # Update package data
$q = sprintf("UPDATE Packages SET ModifiedTS = UNIX_TIMESTAMP(), Name = '%s', Version = '%s-%s', License = '%s', Description = '%s', URL = '%s', LocationID = 2, FSPath = '%s', URLPath = '%s', OutOfDateTS = NULL WHERE ID = %d", $q = sprintf("UPDATE Packages SET ModifiedTS = UNIX_TIMESTAMP(), Name = '%s', Version = '%s-%s', License = '%s', Description = '%s', URL = '%s', LocationID = 2, FSPath = '%s', OutOfDateTS = NULL WHERE ID = %d",
mysql_real_escape_string($new_pkgbuild['pkgname']), mysql_real_escape_string($new_pkgbuild['pkgname']),
mysql_real_escape_string($new_pkgbuild['pkgver']), mysql_real_escape_string($new_pkgbuild['pkgver']),
mysql_real_escape_string($new_pkgbuild['pkgrel']), mysql_real_escape_string($new_pkgbuild['pkgrel']),
...@@ -285,7 +285,6 @@ if ($_COOKIE["AURSID"]): ...@@ -285,7 +285,6 @@ if ($_COOKIE["AURSID"]):
mysql_real_escape_string($new_pkgbuild['pkgdesc']), mysql_real_escape_string($new_pkgbuild['pkgdesc']),
mysql_real_escape_string($new_pkgbuild['url']), mysql_real_escape_string($new_pkgbuild['url']),
mysql_real_escape_string($incoming_pkgdir . "/" . $pkg_name . ".tar.gz"), mysql_real_escape_string($incoming_pkgdir . "/" . $pkg_name . ".tar.gz"),
mysql_real_escape_string(URL_DIR . $pkg_name . "/" . $pkg_name . ".tar.gz"),
$pdata["ID"]); $pdata["ID"]);
db_query($q, $dbh); db_query($q, $dbh);
...@@ -323,7 +322,7 @@ if ($_COOKIE["AURSID"]): ...@@ -323,7 +322,7 @@ if ($_COOKIE["AURSID"]):
$uid = uid_from_sid($_COOKIE["AURSID"]); $uid = uid_from_sid($_COOKIE["AURSID"]);
# This is a brand new package # This is a brand new package
$q = sprintf("INSERT INTO Packages (Name, License, Version, CategoryID, Description, URL, LocationID, SubmittedTS, SubmitterUID, MaintainerUID, FSPath, URLPath) VALUES ('%s', '%s', '%s-%s', %d, '%s', '%s', 2, UNIX_TIMESTAMP(), %d, %d, '%s', '%s')", $q = sprintf("INSERT INTO Packages (Name, License, Version, CategoryID, Description, URL, LocationID, SubmittedTS, SubmitterUID, MaintainerUID, FSPath) VALUES ('%s', '%s', '%s-%s', %d, '%s', '%s', 2, UNIX_TIMESTAMP(), %d, %d, '%s')",
mysql_real_escape_string($new_pkgbuild['pkgname']), mysql_real_escape_string($new_pkgbuild['pkgname']),
mysql_real_escape_string($new_pkgbuild['license']), mysql_real_escape_string($new_pkgbuild['license']),
mysql_real_escape_string($new_pkgbuild['pkgver']), mysql_real_escape_string($new_pkgbuild['pkgver']),
...@@ -333,8 +332,7 @@ if ($_COOKIE["AURSID"]): ...@@ -333,8 +332,7 @@ if ($_COOKIE["AURSID"]):
mysql_real_escape_string($new_pkgbuild['url']), mysql_real_escape_string($new_pkgbuild['url']),
$uid, $uid,
$uid, $uid,
mysql_real_escape_string($incoming_pkgdir . "/" . $pkg_name . ".tar.gz"), mysql_real_escape_string($incoming_pkgdir . "/" . $pkg_name . ".tar.gz"));
mysql_real_escape_string(URL_DIR . $pkg_name . "/" . $pkg_name . ".tar.gz"));
$result = db_query($q, $dbh); $result = db_query($q, $dbh);
$packageID = mysql_insert_id($dbh); $packageID = mysql_insert_id($dbh);
......
...@@ -18,10 +18,23 @@ include_once("aur.inc"); ...@@ -18,10 +18,23 @@ include_once("aur.inc");
**/ **/
class AurJSON { class AurJSON {
private $dbh = false; private $dbh = false;
private $exposed_methods = array('search','info','msearch'); private $exposed_methods = array();
private $fields = array('Packages.ID','Name','Version','CategoryID', private $fields = array();
'Description', 'LocationID', 'URL','URLPath','License','NumVotes',
'(OutOfDateTS IS NOT NULL) AS OutOfDate'); /**
* Initialize methods and database fields.
**/
public function __construct() {
$this->exposed_methods = array('search', 'info', 'msearch');
$this->fields = array(
'Packages.ID', 'Name', 'Version', 'CategoryID',
'Description', 'LocationID', 'URL', 'CONCAT("' .
mysql_real_escape_string(URL_DIR) .
'", Name, "/", Name, ".tar.gz") AS URLPath', 'License',
'NumVotes', '(OutOfDateTS IS NOT NULL) AS OutOfDate'
);
}
/** /**
* Handles post data, and routes the request. * Handles post data, and routes the request.
......
...@@ -173,8 +173,9 @@ $out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("r", intval($row[ ...@@ -173,8 +173,9 @@ $out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("r", intval($row[
$src = $src[0]; $src = $src[0];
# It is presumably an internal source # It is presumably an internal source
if ($row["LocationID"] == 2) { if ($row["LocationID"] == 2) {
echo "<a href='".dirname($row['URLPath'])."/".$row['Name']; $urlpath = URL_DIR . $row['Name'];
echo "/$src'>$src</a><br />\n"; echo "<a href='$urlpath/$src'>";
echo "$src</a><br />\n";
} }
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment