diff options
author | reed@reedloden.com <reed@reedloden.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-01-09 00:40:42 (GMT) |
---|---|---|
committer | reed@reedloden.com <reed@reedloden.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2009-01-09 00:40:42 (GMT) |
commit | 8ae9f0ed461eb067bff5b054cbc19851b6936d66 (patch) | |
tree | 36370e943580e31246229a4ac1f2c114771cec58 /bin | |
parent | 9362c970cbd478cf6e9a70edc85b3121b8ceb5e9 (diff) |
Bug 419906 - "Upgrade install hashes to use SHA-256 instead of SHA-1" [r=clouserw]
git-svn-id: http://svn.mozilla.org/addons/trunk@21480 4eb1ac78-321c-0410-a911-ec516a8615a5
Diffstat (limited to 'bin')
-rw-r--r-- | bin/update-hashes.php | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/bin/update-hashes.php b/bin/update-hashes.php index 1e5612a..5d05833 100644 --- a/bin/update-hashes.php +++ b/bin/update-hashes.php @@ -22,6 +22,7 @@ * Contributor(s): * Mike Morgan <morgamic@mozilla.com> * Justin Scott <fligtar@gmail.com> + * Reed Loden <reed@reedloden.com> * * * @@ -61,55 +62,49 @@ if (isset($_SERVER['HTTP_HOST'])) { exit; } -// If we get here, we're on the command line, which means we can continue. -// Include config file -require_once('../site/app/config/config.php'); -require_once('../site/app/config/constants.php'); +require_once('database.class.php'); + +// New database class +$db = new Database(); $versions = array(); $hashes = array(); -// Connect to our read-only database. -$read = mysql_connect(SHADOW_DB_HOST, SHADOW_DB_USER, SHADOW_DB_PASS) or die('Could not connect: ' . mysql_error()); -mysql_select_db(SHADOW_DB_NAME, $read) or die('Could not select database '.SHADOW_DB_NAME); - -// Connect to our writable database. -$write = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect: ' . mysql_error()); -mysql_select_db(DB_NAME, $write) or die('Could not select database '.DB_NAME); - -$fileQry = mysql_query("SELECT - addons.id as addon_id, - translations.localized_string as name, - versions.version, - files.id as file_id, - files.filename, - files.hash, - files.size - FROM files - INNER JOIN versions ON files.version_id=versions.id - INNER JOIN addons ON versions.addon_id=addons.id - INNER JOIN translations ON addons.name=translations.id - WHERE - translations.locale='en-US'" - , $read); - -while ($fileInfo = mysql_fetch_array($fileQry)) { +$fileQry_sql = "SELECT + addons.id as addon_id, + translations.localized_string as name, + versions.version, + files.id as file_id, + files.filename, + files.hash, + files.size + FROM files + INNER JOIN versions ON files.version_id=versions.id + INNER JOIN addons ON versions.addon_id=addons.id + INNER JOIN translations ON addons.name=translations.id + WHERE + translations.locale='en-US'"; + +$fileQry_result = $db->query($fileQry_sql); + +while ($fileInfo = mysql_fetch_array($fileQry_result)) { $file = REPO_PATH."/{$fileInfo['addon_id']}/{$fileInfo['filename']}"; // If the file exists, get its sum and update its record. if (file_exists($file) && is_file($file)) { - $hash = sha1_file($file); + $hash = hash_file("sha256", $file); $size = round((filesize($file) / 1024), 0); //in KB - + echo "{$fileInfo['name']} {$fileInfo['version']} (file {$fileInfo['file_id']}): "; - if ('sha1:'.$hash != $fileInfo['hash'] || $size != $fileInfo['size']) { - mysql_query("UPDATE files SET hash='sha1:{$hash}', size='{$size}' WHERE id={$fileInfo['file_id']}", $write); - - if ('sha1:'.$hash != $fileInfo['hash']) { - echo "HASH - new: sha1:{$hash}; old: {$fileInfo['hash']}"; + if ('sha256:'.$hash != $fileInfo['hash'] || $size != $fileInfo['size']) { + $hash_update_sql = "UPDATE files SET hash='sha256:{$hash}', size='{$size}' WHERE id={$fileInfo['file_id']}"; + $hash_update_result = $db->query($hash_update_sql, true); + + if ('sha256:'.$hash != $fileInfo['hash']) { + echo "HASH - new: sha256:{$hash}; old: {$fileInfo['hash']}"; } - + if ($size != $fileInfo['size']) { echo "SIZE - new: {$size} KB; old: {$fileInfo['size']} KB"; } @@ -121,5 +116,8 @@ while ($fileInfo = mysql_fetch_array($fileQry)) { } } +// Close our db connection +$db->close(); + exit; ?> |