Commit 0e5c2c80 authored by Thorsten Buss's avatar Thorsten Buss

FIX: remove slash, cause with S3 ver3 SDK, there were removed the first letter of the dir

parent 1920fb23
......@@ -202,7 +202,7 @@ class AdapterAmazonS3Ver2 extends AmazonS3 implements GaufretteAdapter, UrlAware
$this->ensureBucketExists();
// add slash to beginning and remove from end
$prefix = rtrim(preg_replace('/^[\/]*([^\/].*)[\/]?$/', '/$1', $prefix), '/');
$prefix = rtrim(preg_replace('/^[\/]*([^\/].*)[\/]?$/', '$1', $prefix), '/');
return $this->service->getIterator('ListObjects', array(
'Bucket' => $this->bucket,
......@@ -225,7 +225,7 @@ class AdapterAmazonS3Ver2 extends AmazonS3 implements GaufretteAdapter, UrlAware
$keys = array();
$paths = array();
$prefix_dir = rtrim(substr($prefix, -1) != '/'?dirname($prefix):$prefix, '/');
$dirLength = strlen($this->getDirectory() . $prefix_dir) + 1; //+1 to remove the starting slash
$dirLength = ltrim(strlen($this->getDirectory() . $prefix_dir), '/'); // remove the starting slash
foreach ($iterator as $item) {
$file = substr($item['Key'], $dirLength);
if (!$file) continue;
......
<?php
/**
* User: thorsten
* Date: 09.11.15
* Time: 10:28
*/
namespace BNRepo\Tests\Repository;
use BNRepo\Repository\RepositoryManager;
use Symfony\Component\Yaml\Yaml;
class RepositoryS3Test extends \PHPUnit_Framework_TestCase {
function __construct() {
RepositoryManager::reset();
$yml_file = __DIR__ . '/../../../../../tibidono/app/config/repositories.yml';
RepositoryManager::importRepositoriesFromYamlFile($yml_file);
$this->cfg = Yaml::parse($yml_file);
}
public function testDirectoryList() {
$repo = RepositoryManager::getRepository('tibidono-public');
print_r($repo->keys('/shop_uploads/'));
print_r($repo->keys('/shop_voucher_body/756/'));
}
public function testDirectoryList2() {
$repo = RepositoryManager::getRepository('bnrepo-test-local');
print_r($repo->keys('/shop_uploads/'));
}
}
......@@ -230,6 +230,15 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase {
sort($ls);
$this->assertEquals($fileListWithPrefix, $ls, 'directory structure with prefix correct [bothSlashes]');
// Check Prefix (show SubdirPrefix)
$fileListWithPrefix = array(
'testFile1.txt',
);
$ls = $repo->keys('/subdir/subsubdir/', false);
sort($ls);
$this->assertEquals($fileListWithPrefix, $ls, 'directory structure with deep prefix correct');
}
protected function _testCorrectFileStructureWithDirectories(Repository $repo) {
$this->assertEquals(array(), $repo->keys(), 'directory structure empty');
......
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