Commit d6893186 authored by Dries's avatar Dries

- Patch #701358 by aaron, quicksketch, chx, pwolanin, aspilicious: the file...

- Patch #701358 by aaron, quicksketch, chx, pwolanin, aspilicious: the file API presumes a hiearchical file storage.
parent 45dc99c8
......@@ -165,6 +165,8 @@ function file_stream_wrapper_get_class($scheme) {
* @return
* A string containing the name of the scheme, or FALSE if none. For example,
* the URI "public://example.txt" would return "public".
*
* @see file_uri_target()
*/
function file_uri_scheme($uri) {
$data = explode('://', $uri, 2);
......@@ -205,18 +207,14 @@ function file_stream_wrapper_valid_scheme($scheme) {
* A string containing the target (path), or FALSE if none.
* For example, the URI "public://sample/test.txt" would return
* "sample/test.txt".
*
* @see file_uri_scheme()
*/
function file_uri_target($uri) {
$data = explode('://', $uri, 2);
if (count($data) != 2) {
return FALSE;
if ($scheme = file_uri_scheme($uri)) {
return file_stream_wrapper_get_instance_by_scheme($scheme)->getTarget($uri);
}
// Remove erroneous beginning forward slash.
$data[1] = ltrim($data[1], '\/');
return $data[1];
return FALSE;
}
/**
......@@ -225,7 +223,6 @@ function file_uri_target($uri) {
* A stream is referenced as "scheme://target".
*
* The following actions are taken:
* - Remove all occurrences of the wrapper's directory path
* - Remove trailing slashes from target
* - Trim erroneous leading slashes from target. e.g. ":///" becomes "://".
*
......@@ -240,15 +237,9 @@ function file_stream_wrapper_uri_normalize($uri) {
if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
$target = file_uri_target($uri);
// Remove all occurrences of the wrapper's directory path.
$directory_path = file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath();
$target = str_replace($directory_path, '', $target);
// Trim trailing slashes from target.
$target = rtrim($target, '/');
// Trim erroneous leading slashes from target.
$uri = $scheme . '://' . ltrim($target, '/');
if ($target !== FALSE) {
$uri = $scheme . '://' . $target;
}
}
return $uri;
}
......@@ -1880,14 +1871,7 @@ function drupal_dirname($uri) {
$scheme = file_uri_scheme($uri);
if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
$target = file_uri_target($uri);
$dirname = dirname($target);
if ($dirname == '.') {
$dirname = '';
}
return $scheme . '://' . $dirname;
return file_stream_wrapper_get_instance_by_scheme($scheme)->dirname($uri);
}
else {
return dirname($uri);
......
This diff is collapsed.
......@@ -2286,11 +2286,6 @@ class StreamWrapperTest extends DrupalWebTestCase {
$instance = file_stream_wrapper_get_instance_by_uri('public://foo');
$this->assertEqual('DrupalPublicStreamWrapper', get_class($instance), t('Got correct class type for public URI.'));
// Test file_stream_wrapper_uri_normalize().
$uri = 'public:///' . file_directory_path() . '/foo/bar/';
$uri = file_stream_wrapper_uri_normalize($uri);
$this->assertEqual('public://foo/bar', $uri, t('Got a properly normalized URI @uri', array('@uri' => $uri)));
// Test file_uri_target().
$this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
$this->assertFalse(file_uri_target('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment