|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Lukas Reschke <[email protected]> |
| 4 | + * |
| 5 | + * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 6 | + * @license AGPL-3.0 |
| 7 | + * |
| 8 | + * This code is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +namespace OC\Repair; |
| 23 | + |
| 24 | +use OC\Hooks\BasicEmitter; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class BrokenUpdaterRepair fixes some issues caused by bugs in the ownCloud |
| 28 | + * updater below version 9.0.2. |
| 29 | + * |
| 30 | + * FIXME: This file should be removed after the 9.0.2 release. The update server |
| 31 | + * is instructed to deliver 9.0.2 for 9.0.0 and 9.0.1. |
| 32 | + * |
| 33 | + * @package OC\Repair |
| 34 | + */ |
| 35 | +class BrokenUpdaterRepair extends BasicEmitter implements \OC\RepairStep { |
| 36 | + |
| 37 | + public function getName() { |
| 38 | + return 'Manually copies the third-party folder changes since 9.0.0 due ' . |
| 39 | + 'to a bug in the updater.'; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Manually copy the third-party files that have changed since 9.0.0 because |
| 44 | + * the old updater does not copy over third-party changes. |
| 45 | + * |
| 46 | + * @return bool True if action performed, false otherwise |
| 47 | + */ |
| 48 | + private function manuallyCopyThirdPartyFiles() { |
| 49 | + $resourceDir = __DIR__ . '/../../../resources/updater-fixes/'; |
| 50 | + $thirdPartyDir = __DIR__ . '/../../../3rdparty/'; |
| 51 | + |
| 52 | + $filesToCopy = [ |
| 53 | + // Composer updates |
| 54 | + 'composer.json', |
| 55 | + 'composer.lock', |
| 56 | + 'composer/autoload_classmap.php', |
| 57 | + 'composer/installed.json', |
| 58 | + 'composer/LICENSE', |
| 59 | + // Icewind stream library |
| 60 | + 'icewind/streams/src/DirectoryFilter.php', |
| 61 | + 'icewind/streams/src/DirectoryWrapper.php', |
| 62 | + 'icewind/streams/src/RetryWrapper.php', |
| 63 | + 'icewind/streams/src/SeekableWrapper.php', |
| 64 | + // Sabre update |
| 65 | + 'sabre/dav/CHANGELOG.md', |
| 66 | + 'sabre/dav/composer.json', |
| 67 | + 'sabre/dav/lib/CalDAV/Plugin.php', |
| 68 | + 'sabre/dav/lib/CardDAV/Backend/PDO.php', |
| 69 | + 'sabre/dav/lib/DAV/CorePlugin.php', |
| 70 | + 'sabre/dav/lib/DAV/Version.php', |
| 71 | + ]; |
| 72 | + |
| 73 | + // Check the hash for the autoload_classmap.php file, if the hash does match |
| 74 | + // the expected value then the third-party folder has already been copied |
| 75 | + // properly. |
| 76 | + if(hash_file('sha512', $thirdPartyDir . '/composer/autoload_classmap.php') === 'abe09be19b6d427283cbfa7c4156d2c342cd9368d7d0564828a00ae02c435b642e7092cef444f94635f370dbe507eb6b2aa05109b32d8fb5d8a65c3a5a1c658f') { |
| 77 | + $this->emit('\OC\Repair', 'info', ['Third-party files seem already to have been copied. No repair necessary.']); |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + foreach($filesToCopy as $file) { |
| 82 | + $state = copy($resourceDir . '/' . $file, $thirdPartyDir . '/' . $file); |
| 83 | + if($state === true) { |
| 84 | + $this->emit('\OC\Repair', 'info', ['Successfully replaced '.$file.' with new version.']); |
| 85 | + } else { |
| 86 | + $this->emit('\OC\Repair', 'warning', ['Could not replace '.$file.' with new version.']); |
| 87 | + } |
| 88 | + } |
| 89 | + return true; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Rerun the integrity check after the update since the repair step has |
| 94 | + * repaired some invalid copied files. |
| 95 | + */ |
| 96 | + private function recheckIntegrity() { |
| 97 | + \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
| 98 | + } |
| 99 | + |
| 100 | + public function run() { |
| 101 | + if($this->manuallyCopyThirdPartyFiles()) { |
| 102 | + $this->emit('\OC\Repair', 'info', ['Start integrity recheck.']); |
| 103 | + $this->recheckIntegrity(); |
| 104 | + $this->emit('\OC\Repair', 'info', ['Finished integrity recheck.']); |
| 105 | + } else { |
| 106 | + $this->emit('\OC\Repair', 'info', ['Rechecking code integrity not necessary.']); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | + |
0 commit comments