Skip to content

Commit 4d660d8

Browse files
authored
Merge pull request #518 from nextcloud/revert-515-prevent-directory-modifications-when-iterating2
Revert "Prevent directory modifications when iterating"
2 parents 44beafb + 991897b commit 4d660d8

4 files changed

Lines changed: 32 additions & 52 deletions

File tree

index.php

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public function createBackup(): void {
461461
if (!file_exists($backupFolderLocation . '/' . dirname($fileName))) {
462462
$state = mkdir($backupFolderLocation . '/' . dirname($fileName), 0750, true);
463463
if ($state === false) {
464-
throw new \Exception('Could not create folder: ' . $backupFolderLocation . '/' . dirname($fileName));
464+
throw new \Exception('Could not create folder: '.$backupFolderLocation.'/'.dirname($fileName));
465465
}
466466
}
467467

@@ -544,7 +544,7 @@ private function getUpdateServerResponse(): array {
544544
/** @var false|string $response */
545545
$response = curl_exec($curl);
546546
if ($response === false) {
547-
throw new \Exception('Could not do request to updater server: ' . curl_error($curl));
547+
throw new \Exception('Could not do request to updater server: '.curl_error($curl));
548548
}
549549
curl_close($curl);
550550

@@ -737,7 +737,7 @@ private function getVersionByVersionFile(string $versionFile): string {
737737
return implode('.', $OC_Version);
738738
}
739739

740-
throw new \Exception('OC_Version not found in ' . $versionFile);
740+
throw new \Exception("OC_Version not found in $versionFile");
741741
}
742742

743743
/**
@@ -754,15 +754,15 @@ public function extractDownload(): void {
754754
if ($zipState === true) {
755755
$extraction = $zip->extractTo(dirname($downloadedFilePath));
756756
if ($extraction === false) {
757-
throw new \Exception('Error during unpacking zipfile: ' . ($zip->getStatusString()));
757+
throw new \Exception('Error during unpacking zipfile: '.($zip->getStatusString()));
758758
}
759759
$zip->close();
760760
$state = unlink($downloadedFilePath);
761761
if ($state === false) {
762-
throw new \Exception("Could not unlink " . $downloadedFilePath);
762+
throw new \Exception("Can't unlink ". $downloadedFilePath);
763763
}
764764
} else {
765-
throw new \Exception("Can't handle ZIP file. Error code is: " . print_r($zipState, true));
765+
throw new \Exception("Can't handle ZIP file. Error code is: ".print_r($zipState, true));
766766
}
767767

768768
// Ensure that the downloaded version is not lower
@@ -804,7 +804,7 @@ public function replaceEntryPoints(): void {
804804
}
805805
$state = file_put_contents($this->baseDir . '/../' . $file, $content);
806806
if ($state === false) {
807-
throw new \Exception('Can\'t replace entry point: ' . $file);
807+
throw new \Exception('Can\'t replace entry point: '.$file);
808808
}
809809
}
810810

@@ -841,14 +841,10 @@ private function recursiveDelete(string $folder): void {
841841
}
842842

843843
foreach ($files as $file) {
844-
if (unlink($file) === false) {
845-
throw new \Exception('Could not unlink ' . $file);
846-
}
844+
unlink($file);
847845
}
848846
foreach ($directories as $dir) {
849-
if (rmdir($dir) === false) {
850-
throw new \Exception('Could not rmdir ' . $dir);
851-
}
847+
rmdir($dir);
852848
}
853849

854850
$state = rmdir($folder);
@@ -937,10 +933,7 @@ public function deleteOldFiles(): void {
937933
* @var string $path
938934
* @var \SplFileInfo $fileInfo
939935
*/
940-
// Build file list first, so the removals won't mess with it
941-
/** @var array<string, \SplFileInfo> */
942-
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true);
943-
foreach ($fileList as $path => $fileInfo) {
936+
foreach ($this->getRecursiveDirectoryIterator() as $path => $fileInfo) {
944937
$currentDir = $this->baseDir . '/../';
945938
$fileName = explode($currentDir, $path)[1];
946939
$folderStructure = explode('/', $fileName, -1);
@@ -957,7 +950,7 @@ public function deleteOldFiles(): void {
957950
if ($fileInfo->isFile() || $fileInfo->isLink()) {
958951
$state = unlink($path);
959952
if ($state === false) {
960-
throw new \Exception('Could not unlink: ' . $path);
953+
throw new \Exception('Could not unlink: '.$path);
961954
}
962955
} elseif ($fileInfo->isDir()) {
963956
$state = rmdir($path);
@@ -980,10 +973,7 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement
980973
* @var string $path
981974
* @var \SplFileInfo $fileInfo
982975
*/
983-
// Build file list first, so the renames won't mess with it
984-
/** @var array<string, \SplFileInfo> */
985-
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator($dataLocation), true);
986-
foreach ($fileList as $path => $fileInfo) {
976+
foreach ($this->getRecursiveDirectoryIterator($dataLocation) as $path => $fileInfo) {
987977
$fileName = explode($dataLocation, $path)[1];
988978
$folderStructure = explode('/', $fileName, -1);
989979

@@ -1064,12 +1054,12 @@ public function finalize(): void {
10641054
$this->moveWithExclusions($storageLocation, []);
10651055
$state = rmdir($storageLocation);
10661056
if ($state === false) {
1067-
throw new \Exception('Could not rmdir ' . $storageLocation);
1057+
throw new \Exception('Could not rmdir $storagelocation');
10681058
}
10691059

10701060
$state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/.step');
10711061
if ($state === false) {
1072-
throw new \Exception('Could not unlink .step');
1062+
throw new \Exception('Could not rmdir .step');
10731063
}
10741064

10751065
if (function_exists('opcache_reset')) {
@@ -1089,7 +1079,7 @@ private function writeStep(string $state, int $step): void {
10891079
if (!file_exists($updaterDir)) {
10901080
$result = mkdir($updaterDir);
10911081
if ($result === false) {
1092-
throw new \Exception('Could not create ' . $updaterDir);
1082+
throw new \Exception('Could not create $updaterDir');
10931083
}
10941084
}
10951085
$result = touch($updaterDir . '/.step');

lib/Updater.php

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function createBackup(): void {
423423
if (!file_exists($backupFolderLocation . '/' . dirname($fileName))) {
424424
$state = mkdir($backupFolderLocation . '/' . dirname($fileName), 0750, true);
425425
if ($state === false) {
426-
throw new \Exception('Could not create folder: ' . $backupFolderLocation . '/' . dirname($fileName));
426+
throw new \Exception('Could not create folder: '.$backupFolderLocation.'/'.dirname($fileName));
427427
}
428428
}
429429

@@ -506,7 +506,7 @@ private function getUpdateServerResponse(): array {
506506
/** @var false|string $response */
507507
$response = curl_exec($curl);
508508
if ($response === false) {
509-
throw new \Exception('Could not do request to updater server: ' . curl_error($curl));
509+
throw new \Exception('Could not do request to updater server: '.curl_error($curl));
510510
}
511511
curl_close($curl);
512512

@@ -699,7 +699,7 @@ private function getVersionByVersionFile(string $versionFile): string {
699699
return implode('.', $OC_Version);
700700
}
701701

702-
throw new \Exception('OC_Version not found in ' . $versionFile);
702+
throw new \Exception("OC_Version not found in $versionFile");
703703
}
704704

705705
/**
@@ -716,15 +716,15 @@ public function extractDownload(): void {
716716
if ($zipState === true) {
717717
$extraction = $zip->extractTo(dirname($downloadedFilePath));
718718
if ($extraction === false) {
719-
throw new \Exception('Error during unpacking zipfile: ' . ($zip->getStatusString()));
719+
throw new \Exception('Error during unpacking zipfile: '.($zip->getStatusString()));
720720
}
721721
$zip->close();
722722
$state = unlink($downloadedFilePath);
723723
if ($state === false) {
724-
throw new \Exception("Could not unlink " . $downloadedFilePath);
724+
throw new \Exception("Can't unlink ". $downloadedFilePath);
725725
}
726726
} else {
727-
throw new \Exception("Can't handle ZIP file. Error code is: " . print_r($zipState, true));
727+
throw new \Exception("Can't handle ZIP file. Error code is: ".print_r($zipState, true));
728728
}
729729

730730
// Ensure that the downloaded version is not lower
@@ -766,7 +766,7 @@ public function replaceEntryPoints(): void {
766766
}
767767
$state = file_put_contents($this->baseDir . '/../' . $file, $content);
768768
if ($state === false) {
769-
throw new \Exception('Can\'t replace entry point: ' . $file);
769+
throw new \Exception('Can\'t replace entry point: '.$file);
770770
}
771771
}
772772

@@ -803,14 +803,10 @@ private function recursiveDelete(string $folder): void {
803803
}
804804

805805
foreach ($files as $file) {
806-
if (unlink($file) === false) {
807-
throw new \Exception('Could not unlink ' . $file);
808-
}
806+
unlink($file);
809807
}
810808
foreach ($directories as $dir) {
811-
if (rmdir($dir) === false) {
812-
throw new \Exception('Could not rmdir ' . $dir);
813-
}
809+
rmdir($dir);
814810
}
815811

816812
$state = rmdir($folder);
@@ -899,10 +895,7 @@ public function deleteOldFiles(): void {
899895
* @var string $path
900896
* @var \SplFileInfo $fileInfo
901897
*/
902-
// Build file list first, so the removals won't mess with it
903-
/** @var array<string, \SplFileInfo> */
904-
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true);
905-
foreach ($fileList as $path => $fileInfo) {
898+
foreach ($this->getRecursiveDirectoryIterator() as $path => $fileInfo) {
906899
$currentDir = $this->baseDir . '/../';
907900
$fileName = explode($currentDir, $path)[1];
908901
$folderStructure = explode('/', $fileName, -1);
@@ -919,7 +912,7 @@ public function deleteOldFiles(): void {
919912
if ($fileInfo->isFile() || $fileInfo->isLink()) {
920913
$state = unlink($path);
921914
if ($state === false) {
922-
throw new \Exception('Could not unlink: ' . $path);
915+
throw new \Exception('Could not unlink: '.$path);
923916
}
924917
} elseif ($fileInfo->isDir()) {
925918
$state = rmdir($path);
@@ -942,10 +935,7 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement
942935
* @var string $path
943936
* @var \SplFileInfo $fileInfo
944937
*/
945-
// Build file list first, so the renames won't mess with it
946-
/** @var array<string, \SplFileInfo> */
947-
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator($dataLocation), true);
948-
foreach ($fileList as $path => $fileInfo) {
938+
foreach ($this->getRecursiveDirectoryIterator($dataLocation) as $path => $fileInfo) {
949939
$fileName = explode($dataLocation, $path)[1];
950940
$folderStructure = explode('/', $fileName, -1);
951941

@@ -1026,12 +1016,12 @@ public function finalize(): void {
10261016
$this->moveWithExclusions($storageLocation, []);
10271017
$state = rmdir($storageLocation);
10281018
if ($state === false) {
1029-
throw new \Exception('Could not rmdir ' . $storageLocation);
1019+
throw new \Exception('Could not rmdir $storagelocation');
10301020
}
10311021

10321022
$state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/.step');
10331023
if ($state === false) {
1034-
throw new \Exception('Could not unlink .step');
1024+
throw new \Exception('Could not rmdir .step');
10351025
}
10361026

10371027
if (function_exists('opcache_reset')) {
@@ -1051,7 +1041,7 @@ private function writeStep(string $state, int $step): void {
10511041
if (!file_exists($updaterDir)) {
10521042
$result = mkdir($updaterDir);
10531043
if ($result === false) {
1054-
throw new \Exception('Could not create ' . $updaterDir);
1044+
throw new \Exception('Could not create $updaterDir');
10551045
}
10561046
}
10571047
$result = touch($updaterDir . '/.step');

updater.phar

-468 Bytes
Binary file not shown.

vendor/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => '14ccc22088938656fb221e3d7f7e8928a58332ab',
6+
'reference' => 'aac9e4b1f9edc88a0d28dcbfca50276c9a2c25ba',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => '14ccc22088938656fb221e3d7f7e8928a58332ab',
16+
'reference' => 'aac9e4b1f9edc88a0d28dcbfca50276c9a2c25ba',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../../',
1919
'aliases' => array(),

0 commit comments

Comments
 (0)