From 0ff07f55dd094610f0ba1aa9fca8412ffa3a01dd Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 20 Oct 2023 15:02:14 +0200 Subject: [PATCH 1/2] oum install checks --- .../lib/UpdateManager/Client.php | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/pandora_console/update_manager_client/lib/UpdateManager/Client.php b/pandora_console/update_manager_client/lib/UpdateManager/Client.php index 42d9e6367a..32f37dfd29 100644 --- a/pandora_console/update_manager_client/lib/UpdateManager/Client.php +++ b/pandora_console/update_manager_client/lib/UpdateManager/Client.php @@ -1246,6 +1246,34 @@ class Client } + private function getDirectorySize($directory) + { + if (is_string($directory) === false || is_dir($directory) === false) { + throw new \InvalidArgumentException('Invalid directory path'); + } + + $size = 0; + + if ($handle = opendir($directory)) { + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..') { + $path = $directory.DIRECTORY_SEPARATOR.$file; + if (is_dir($path) === true) { + // Recursive call for subdirectories. + $size += $this->getDirectorySize($path); + } else { + $size += filesize($path); + } + } + } + + closedir($handle); + } + + return $size; + } + + /** * Update files. * @@ -1263,7 +1291,8 @@ class Client string $from, string $to, bool $test=false, - bool $classic=false + bool $classic=false, + bool $called_recursively=false ) :void { if (is_dir($from) !== true || is_readable($from) !== true) { throw new \Exception('Cannot access patch files '.$from); @@ -1284,6 +1313,18 @@ class Client throw new \Exception('Files are not readable'); } + if ($test === true && $called_recursively === false) { + // Get size of folder and its subfolders corresponding to "from" path containing those files + // that will be updated in product. + // Do once. + $source_size = $this->getDirectorySize($from); + $source_size = 999999999999; + // Check available disk space before writing files. + if (disk_free_space($to) < $source_size) { + throw new \Exception('Not enough disk space to write the files'); + } + } + $created_directories = []; while (($pf = readdir($pd)) !== false) { @@ -1308,11 +1349,13 @@ class Client $created_directories[] = $dest; } - $this->updateFiles($version, $pf.'/', $to, $test, $classic); + $this->updateFiles($version, $pf.'/', $to, $test, $classic, true); } else { // It's a file. if ($test === true) { - if (is_writable($target_folder) !== true) { + if (is_writable($target_folder) !== true + || (file_exists($dest) === true && is_writable($dest) !== true) + ) { throw new \Exception($dest.' is not writable'); } } else { From 2688d7033257279418eb349cf9326ec191222cb5 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 23 Oct 2023 15:50:01 +0200 Subject: [PATCH 2/2] oum update checks --- .../update_manager_client/lib/UpdateManager/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/update_manager_client/lib/UpdateManager/Client.php b/pandora_console/update_manager_client/lib/UpdateManager/Client.php index 32f37dfd29..f8c584c5a9 100644 --- a/pandora_console/update_manager_client/lib/UpdateManager/Client.php +++ b/pandora_console/update_manager_client/lib/UpdateManager/Client.php @@ -1318,7 +1318,7 @@ class Client // that will be updated in product. // Do once. $source_size = $this->getDirectorySize($from); - $source_size = 999999999999; + // Check available disk space before writing files. if (disk_free_space($to) < $source_size) { throw new \Exception('Not enough disk space to write the files');