From 993ae23e76cce799db8f2fe6a6f67337e5771d4f Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Thu, 8 Dec 2011 12:14:25 +1300 Subject: [PATCH 1/3] refs @fiasco/Archimedes-Library#1 - test the dir() call --- php/archimedes.class.php | 83 ++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/php/archimedes.class.php b/php/archimedes.class.php index 4c7ba9e..84171a9 100644 --- a/php/archimedes.class.php +++ b/php/archimedes.class.php @@ -542,45 +542,52 @@ function archimedes_directory_hash($dir, $ignore) { } $filemd5s = array(); - $d = dir($dir); - - while (($entry = $d->read()) !== false) { - if (in_array($entry, array('.', '..'))) { - continue; - } - $path = realpath($dir . '/' . $entry); - // If the begining of the path does not match exactly then - // this directory does not lead deeper but to somewhere else which - // may create a recursive loop. - if (strpos($path, $dir) !== 0) { - $symlinks[] = $path; - continue; - } - // Symlinks may introduce recursive loops. - if (is_link($path)) { - $symlinks[] = $path; - continue; - } - $ignore_entry = FALSE; - foreach($ignore as $pattern) { - if(preg_match($pattern, $path)) { - $ignore_entry = TRUE; - break; + + if ($d = dir($dir)) { + while (($entry = $d->read()) !== false) { + if (in_array($entry, array('.', '..'))) { + continue; + } + $path = realpath($dir . '/' . $entry); + // If the begining of the path does not match exactly then + // this directory does not lead deeper but to somewhere else which + // may create a recursive loop. + if (strpos($path, $dir) !== 0) { + $symlinks[] = $path; + continue; + } + // Symlinks may introduce recursive loops. + if (is_link($path)) { + $symlinks[] = $path; + continue; + } + $ignore_entry = FALSE; + foreach($ignore as $pattern) { + if(preg_match($pattern, $path)) { + $ignore_entry = TRUE; + break; + } + } + if ($ignore_entry) { + continue; + } + if (is_dir($path)) { + $filemd5s[] = archimedes_directory_hash($path, $ignore); + } + elseif (is_file($path)) { + $filemd5s[] = md5_file($path); } } - if ($ignore_entry) { - continue; - } - if (is_dir($path)) { - $filemd5s[] = archimedes_directory_hash($path, $ignore); - } - elseif (is_file($path)) { - $filemd5s[] = md5_file($path); - } - } - $d->close(); - //sort the md5s before concat so ensure order of files doesn't affect it. - asort($filemd5s); - return md5(implode('', $filemd5s) . implode('', $symlinks)); + $d->close(); + //sort the md5s before concat so ensure order of files doesn't affect it. + asort($filemd5s); + return md5(implode('', $filemd5s) . implode('', $symlinks)); + } + else { + /** + * return an error usefully - if we weren't in an external library + * then this would be a watchdog() statement + */ + } } From 0afdd2dbd9399959efaaa32fd8c06a322e4efa15 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Sat, 5 May 2012 11:24:46 +1200 Subject: [PATCH 2/3] Test readability of files / dirs before. Untested commit. --- php/archimedes.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/archimedes.class.php b/php/archimedes.class.php index 84171a9..89921b8 100644 --- a/php/archimedes.class.php +++ b/php/archimedes.class.php @@ -563,7 +563,7 @@ function archimedes_directory_hash($dir, $ignore) { } $ignore_entry = FALSE; foreach($ignore as $pattern) { - if(preg_match($pattern, $path)) { + if(preg_match($pattern, $path) || !is_readable($path)) { $ignore_entry = TRUE; break; } From 4bb479ac39442082c5bb26b46056111480b15801 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Sun, 13 May 2012 22:54:04 +1200 Subject: [PATCH 3/3] If the Archimedes server responds with an HTTP error, we should pass that back. Better than "Update failed to send for an unknown reason". --- php/archimedes.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/archimedes.class.php b/php/archimedes.class.php index 89921b8..278bcc2 100644 --- a/php/archimedes.class.php +++ b/php/archimedes.class.php @@ -75,7 +75,7 @@ protected function getEncrypted() { public function __toString() { return base64_encode($this->getEncrypted()); - } + } /** * Post the data directly to the Archimedes Server. @@ -174,7 +174,7 @@ public function postXML($server_url) { case 307: // Moved temporarily break; default: - return FALSE; + throw new Exception('Unable to submit data. Archimedes server returned HTTP code ' . $code . ', ' . $text); } $status = json_decode($result); return $status->success; @@ -584,7 +584,7 @@ function archimedes_directory_hash($dir, $ignore) { asort($filemd5s); return md5(implode('', $filemd5s) . implode('', $symlinks)); } - else { + else { /** * return an error usefully - if we weren't in an external library * then this would be a watchdog() statement