diff --git a/pinc/CharSuites.inc b/pinc/CharSuites.inc index 9e85639e7..ac6364501 100644 --- a/pinc/CharSuites.inc +++ b/pinc/CharSuites.inc @@ -147,7 +147,9 @@ class CharSuites return; } - $charsuite_files = glob($relPath."charsuite-*.inc"); + if (($charsuite_files = glob($relPath."charsuite-*.inc")) === false) { + throw new RuntimeException(_("Failed to load CharSuites files.")); + } foreach ($charsuite_files as $charsuite_file) { include($charsuite_file); } diff --git a/pinc/Project.inc b/pinc/Project.inc index ce82603e3..d844c8848 100644 --- a/pinc/Project.inc +++ b/pinc/Project.inc @@ -1316,7 +1316,12 @@ class Project $db_names = $this->get_page_names_from_db(); chdir($this->dir); - $disk_names = glob("*.{png,jpg}", GLOB_BRACE); + if (($disk_names = glob("*.{png,jpg}", GLOB_BRACE)) === false) { + throw new RuntimeException(sprintf( + _("Failed to list page images for %s."), + $this->projectid + )); + } sort($disk_names); return array_intersect($db_names, $disk_names); } @@ -1347,7 +1352,12 @@ class Project $page_image_names = $this->get_page_names_from_db(); chdir($this->dir); - $existing_image_names = glob("*.{png,jpg}", GLOB_BRACE); + if (($existing_image_names = glob("*.{png,jpg}", GLOB_BRACE)) === false) { + throw new RuntimeException(sprintf( + _("Failed to list page images for %s."), + $this->projectid + )); + } sort($existing_image_names); return array_diff($existing_image_names, $page_image_names); } diff --git a/pinc/archiving.inc b/pinc/archiving.inc index c299cec7d..db28b541c 100644 --- a/pinc/archiving.inc +++ b/pinc/archiving.inc @@ -72,7 +72,13 @@ function archive_project(Project $project, bool $dry_run = false): void echo " Move $project_dir to $new_dir.\n"; } else { // Remove uncompressed versions of whole-project texts, leaving zips. - foreach (glob("$project_dir/projectID*.txt") as $filename) { + if (($filenames = glob("$project_dir/projectID*.txt")) === false) { + throw new RuntimeException(sprintf( + _("Failed to list whole-project texts when archiving %s."), + $projectid + )); + } + foreach ($filenames as $filename) { if (!unlink($filename)) { throw new RuntimeException(sprintf(_("Unable to delete %s"), $filename)); } diff --git a/pinc/iso_lang_list.inc b/pinc/iso_lang_list.inc index 2406a0f6a..01065a48d 100644 --- a/pinc/iso_lang_list.inc +++ b/pinc/iso_lang_list.inc @@ -15,8 +15,10 @@ function get_languages_with_dictionaries(): array global $aspell_prefix; $returnArray = []; - - foreach (glob("$aspell_prefix/lib/aspell/*.multi") as $filename) { + if (($filenames = glob("$aspell_prefix/lib/aspell/*.multi")) === false) { + throw new RuntimeException(_("Failed to list aspell dictionaries.")); + } + foreach ($filenames as $filename) { // dictionaries need to map to a two- or three-letter language code if (preg_match("#/(\w{2,3})\.multi\$#", $filename, $matches)) { $langname = langname_for_langcode($matches[1]); diff --git a/pinc/project_quick_check.inc b/pinc/project_quick_check.inc index 3e9199f7f..ed7bb4706 100644 --- a/pinc/project_quick_check.inc +++ b/pinc/project_quick_check.inc @@ -320,7 +320,12 @@ function _test_project_for_illo_images(string $projectid): PQCResult $page_image_names = $project->get_page_names_from_db(); chdir($project->dir); - $existing_image_names = glob("*.{png,jpg}", GLOB_BRACE); + if (($existing_image_names = glob("*.{png,jpg}", GLOB_BRACE)) === false) { + throw new RuntimeException(sprintf( + _("Failed to list page images for %s."), + $project->projectid + )); + } // That returns a sorted list of the .png files // followed by a sorted list of the .jpg files, // but we want the two lists interleaved... diff --git a/pinc/showavailablebooks.inc b/pinc/showavailablebooks.inc index 4cd22853a..37f58d0ed 100644 --- a/pinc/showavailablebooks.inc +++ b/pinc/showavailablebooks.inc @@ -554,11 +554,13 @@ function show_project_listing( // Uploaded is a special case because it is pulled from the // filesystem and not from the database, and is hence not sortable. global $projects_dir; - if ($done_files = glob("$projects_dir/{$book['projectid']}/*smooth_done_*.zip")) { - $num_done = count($done_files); - } else { - $num_done = 0; + if (($done_files = glob("$projects_dir/{$book['projectid']}/*smooth_done_*.zip")) === false) { + throw new RuntimeException(sprintf( + _("Failed to list smoothread uploads for %s."), + $book['projectid'] + )); } + $num_done = count($done_files); $cell = $num_done; } elseif ($col_id == "days_avail" || $col_id == "days_left") { $cell = sprintf("%.1f", $book[$col_id]);