summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/catalog.class.php12
-rw-r--r--lib/class/core.class.php56
-rw-r--r--play/index.php6
3 files changed, 48 insertions, 26 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 73e8b479..89167eca 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -217,13 +217,11 @@ class Catalog extends database_object {
// Make sure the path is readable/exists
if ($data['type'] == 'local') {
- $handle = opendir($path);
- if ($handle === false) {
+ if (!Core::is_readable($path)) {
debug_event('catalog', 'Cannot add catalog at unopenable path ' . $path, 1);
Error::add('general', sprintf(T_('Error: %s is not readable or does not exist'), scrub_out($data['path'])));
return false;
}
- closedir($handle);
}
// Make sure this path isn't already in use by an existing catalog
@@ -501,7 +499,7 @@ class Catalog extends database_object {
Error::add('catalog_add', sprintf(T_('Error: Unable to get filesize for %s'), $full_file));
} // file_size check
- if (!is_readable($full_file)) {
+ if (!Core::is_readable($full_file)) {
// not readable, warn user
debug_event('read', "$full_file is not readable by ampache", 2);
/* HINT: FullFile */
@@ -1175,7 +1173,7 @@ class Catalog extends database_object {
* Removes local songs that no longer exist.
*/
private function clean_local_catalog() {
- if (!is_readable($this->path)) {
+ if (!Core::is_readable($this->path)) {
// First sanity check; no point in proceeding with an unreadable
// catalog root.
debug_event('catalog', 'Catalog path:' . $this->path . ' unreadable, clean failed', 1);
@@ -1288,7 +1286,7 @@ class Catalog extends database_object {
$dead[] = $results['id'];
} //if error
- else if (!is_readable($results['file'])) {
+ else if (!Core::is_readable($results['file'])) {
debug_event('clean', $results['file'] . ' is not readable, but does exist', 1);
}
}
@@ -1373,7 +1371,7 @@ class Catalog extends database_object {
UI::update_text('verify_dir_' . $this->id, scrub_out($file));
}
- if (!is_readable($row['file'])) {
+ if (!Core::is_readable($row['file'])) {
Error::add('general', sprintf(T_('%s does not exist or is not readable'), $row['file']));
debug_event('read', $row['file'] . ' does not exist or is not readable', 5);
continue;
diff --git a/lib/class/core.class.php b/lib/class/core.class.php
index 55e594d5..5619225c 100644
--- a/lib/class/core.class.php
+++ b/lib/class/core.class.php
@@ -41,27 +41,27 @@ class Core {
/**
* autoload
- * This function automatically loads any missing classes as they are
- * needed so that we don't use a million include statements which load
- * more than we need.
+ * This function automatically loads any missing classes as they are
+ * needed so that we don't use a million include statements which load
+ * more than we need.
*/
public static function autoload($class) {
- // Lowercase the class
- $class = strtolower($class);
+ // Lowercase the class
+ $class = strtolower($class);
- $file = Config::get('prefix') . "/lib/class/$class.class.php";
+ $file = Config::get('prefix') . "/lib/class/$class.class.php";
- // See if it exists
- if (is_readable($file)) {
- require $file;
- if (is_callable($class . '::_auto_init')) {
- $class::_auto_init();
- }
- }
- // Else log this as a fatal error
- else {
- debug_event('autoload', "'$class' not found!", 1);
+ // See if it exists
+ if (Core::is_readable($file)) {
+ require $file;
+ if (is_callable($class . '::_auto_init')) {
+ $class::_auto_init();
}
+ }
+ // Else log this as a fatal error
+ else {
+ debug_event('autoload', "'$class' not found!", 1);
+ }
} // autoload
/**
@@ -164,5 +164,29 @@ class Core {
} // image_dimensions
+ /*
+ * is_readable
+ *
+ * Replacement function because PHP's is_readable is buggy:
+ * https://bugs.php.net/bug.php?id=49620
+ */
+ public static function is_readable($path) {
+ if (is_dir($path)) {
+ $handle = opendir($path);
+ if ($handle === false) {
+ return false;
+ }
+ closedir($handle);
+ return true;
+ }
+
+ $handle = fopen($path, 'rb');
+ if ($handle === false) {
+ return false;
+ }
+ fclose($handle);
+ return true;
+ }
+
} // Core
?>
diff --git a/play/index.php b/play/index.php
index 4500a7ad..1b4c4abf 100644
--- a/play/index.php
+++ b/play/index.php
@@ -230,10 +230,10 @@ if ($catalog->catalog_type == 'remote') {
}
/* If we don't have a file, or the file is not readable */
-if (!$media->file OR !is_readable($media->file)) {
+if (!$media->file || !Core::is_readable($media->file)) {
- // We need to make sure this isn't democratic play, if it is then remove the song
- // from the vote list
+ // We need to make sure this isn't democratic play, if it is then remove
+ // the song from the vote list
if (is_object($tmp_playlist)) {
$tmp_playlist->delete_track($oid);
}