From 9e73c46bccd99efb773850acb73586339bbe2576 Mon Sep 17 00:00:00 2001 From: Doug Stevenson Date: Thu, 9 Jul 2015 11:53:33 -0700 Subject: [PATCH 1/2] bugfix(S3/StreamWrapper) Init protocol from passed path. Protocols are enforced by PHP to match. Issue #693 --- src/S3/StreamWrapper.php | 1 + tests/S3/StreamWrapperTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/S3/StreamWrapper.php b/src/S3/StreamWrapper.php index c4bef0f3bf..241370e956 100644 --- a/src/S3/StreamWrapper.php +++ b/src/S3/StreamWrapper.php @@ -515,6 +515,7 @@ private function formatKey($key) */ public function rename($path_from, $path_to) { + $this->initProtocol($path_from); $partsFrom = $this->withPath($path_from); $partsTo = $this->withPath($path_to); $this->clearCacheKey($path_from); diff --git a/tests/S3/StreamWrapperTest.php b/tests/S3/StreamWrapperTest.php index 2d1d352792..a14698d59a 100644 --- a/tests/S3/StreamWrapperTest.php +++ b/tests/S3/StreamWrapperTest.php @@ -407,6 +407,16 @@ public function testCanDeleteNestedFolderWithRmDir() $this->assertEquals('/foo/bar/', $entries[1]['request']->getUri()->getPath()); } + /** + * @expectedException \PHPUnit_Framework_Error_Warning + * @expectedExceptionMessage rename(): Cannot rename a file across wrapper types + */ + public function testRenameEnsuresProtocolsMatch() + { + StreamWrapper::register($this->client, 'baz'); + rename('s3://foo/bar', 'baz://qux/quux'); + } + /** * @expectedException \PHPUnit_Framework_Error_Warning * @expectedExceptionMessage The Amazon S3 stream wrapper only supports copying objects From 6db66f4753b2e5eacf5bf5df82daad49d0b25c06 Mon Sep 17 00:00:00 2001 From: Doug Stevenson Date: Thu, 9 Jul 2015 13:29:40 -0700 Subject: [PATCH 2/2] chore(S3/StreamWrapper) Add comment about implicit functionality. --- src/S3/StreamWrapper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/S3/StreamWrapper.php b/src/S3/StreamWrapper.php index 241370e956..333956d073 100644 --- a/src/S3/StreamWrapper.php +++ b/src/S3/StreamWrapper.php @@ -515,6 +515,8 @@ private function formatKey($key) */ public function rename($path_from, $path_to) { + // PHP will not allow rename across wrapper types, so we can safely + // assume $path_from and $path_to have the same protocol $this->initProtocol($path_from); $partsFrom = $this->withPath($path_from); $partsTo = $this->withPath($path_to);