Store SHA-256 hashes in `wcf1_package_installation_file_log`
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 28 Jul 2022 09:25:01 +0000 (11:25 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 28 Jul 2022 09:51:55 +0000 (11:51 +0200)
It is not planned to actively check them anywhere, but having something is
often better than needing them. They might ease manual verification of the
installation's consistency.

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.6.php
wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php
wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index e94541bbf0d4e3c998d3ae67b9b2667f1afbf1c4..71e99b617172dbd48dfd571bba0051e9c6482fdd 100644 (file)
@@ -9,8 +9,10 @@
  * @package WoltLabSuite\Core
  */
 
+use wcf\system\database\table\column\BigintDatabaseTableColumn;
 use wcf\system\database\table\column\NotNullInt10DatabaseTableColumn;
 use wcf\system\database\table\column\TinyintDatabaseTableColumn;
+use wcf\system\database\table\column\VarbinaryDatabaseTableColumn;
 use wcf\system\database\table\PartialDatabaseTable;
 
 return [
@@ -25,6 +27,12 @@ return [
     PartialDatabaseTable::create('wcf1_package_installation_file_log')
         ->columns([
             NotNullInt10DatabaseTableColumn::create('packageID'),
+            VarbinaryDatabaseTableColumn::create('sha256')
+                ->length(32)
+                ->defaultValue(null),
+            BigintDatabaseTableColumn::create('lastUpdated')
+                ->length(20)
+                ->defaultValue(null),
         ]),
     PartialDatabaseTable::create('wcf1_package_installation_plugin')
         ->columns([
index 2133591bd0cf84ea12e77b6c74a54568ad6f92e0..37f9de5e19186fd50c7df97adf138094cd05c118 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\system\package;
 
+use wcf\data\application\Application;
 use wcf\data\package\Package;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
@@ -61,9 +62,13 @@ class FilesFileHandler extends PackageInstallationFileHandler
             return;
         }
 
-        $sql = "INSERT IGNORE INTO  wcf" . WCF_N . "_package_installation_file_log
-                                    (packageID, filename, application)
-                VALUES              (?, ?, ?)";
+        $baseDirectory = Application::getDirectory($this->application);
+
+        $sql = "INSERT INTO             wcf1_package_installation_file_log
+                                        (packageID, filename, application, sha256, lastUpdated)
+                VALUES                  (?, ?, ?, ?, ?)
+                ON DUPLICATE KEY UPDATE sha256 = VALUES(sha256),
+                                        lastUpdated = VALUES(lastUpdated)";
         $statement = WCF::getDB()->prepareStatement($sql);
 
         WCF::getDB()->beginTransaction();
@@ -72,6 +77,8 @@ class FilesFileHandler extends PackageInstallationFileHandler
                 $this->packageInstallation->getPackageID(),
                 $file,
                 $this->application,
+                \hash_file('sha256', $baseDirectory . $file, true),
+                TIME_NOW,
             ]);
         }
         WCF::getDB()->commitTransaction();
index f72ff426bb1546d0af327d18aba9bf05dbd631c6..e15d102cd0874ae3a5606ffeec7c981ae0b08434 100644 (file)
@@ -69,19 +69,21 @@ class FilePackageInstallationPlugin extends AbstractPackageInstallationPlugin im
 
             // log files
             $sql = "INSERT INTO wcf" . WCF_N . "_package_installation_file_log
-                                (packageID, filename, application)
-                    VALUES      (?, ?, ?)";
+                                (packageID, filename, application, sha256, lastUpdated)
+                    VALUES      (?, ?, ?, ?, ?)";
             $statement = WCF::getDB()->prepareStatement($sql);
-            $statement->execute([
-                $this->installation->getPackageID(),
-                'config.inc.php',
-                Package::getAbbreviation($this->installation->getPackage()->package),
-            ]);
-            $statement->execute([
-                $this->installation->getPackageID(),
+            foreach ([
                 PackageInstallationDispatcher::CONFIG_FILE,
-                Package::getAbbreviation($this->installation->getPackage()->package),
-            ]);
+                'config.inc.php',
+            ] as $filename) {
+                $statement->execute([
+                    $this->installation->getPackageID(),
+                    $filename,
+                    Package::getAbbreviation($this->installation->getPackage()->package),
+                    \hash_file('sha256', $packageDir . $filename, true),
+                    \TIME_NOW,
+                ]);
+            }
 
             // load application
             WCF::loadRuntimeApplication($this->installation->getPackageID());
index 8be229875a6e713bbcd3807646967ee5c9723fc7..07685b4da6fc52ef630722568b00eda5843026d1 100644 (file)
@@ -956,6 +956,8 @@ CREATE TABLE wcf1_package_installation_file_log (
        packageID INT(10) NOT NULL,
        filename VARBINARY(765) NOT NULL, -- VARBINARY(765) roughly equals VARCHAR(255)
        application VARCHAR(20) NOT NULL,
+       sha256 VARBINARY(32) DEFAULT NULL,
+       lastUpdated BIGINT(20) DEFAULT NULL,
        UNIQUE KEY applicationFile (application, filename)
 );