Skip to content

Commit 46b644a

Browse files
Merge branch '2.4-develop' into graphql-api-enhancements
2 parents cd52ad3 + 91cb4d4 commit 46b644a

File tree

9 files changed

+186
-71
lines changed

9 files changed

+186
-71
lines changed

app/code/Magento/AwsS3/Test/Mftf/Helper/DummyMetadataCache.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@ public function updateMetadata(string $path, array $objectMetadata, bool $persis
8383
public function storeFileNotExists(string $path): void
8484
{
8585
}
86+
87+
/**
88+
* @inheirtDoc
89+
*/
90+
public function storeDirNotExists(string $path): void
91+
{
92+
}
8693
}

app/code/Magento/AwsS3/Test/Mftf/Helper/S3FileAssertions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class S3FileAssertions extends Helper
2626
*/
2727
private $driver;
2828

29+
/**
30+
* @var AwsS3V3Adapter
31+
*/
32+
private $adapter;
33+
2934
/**
3035
* Call the parent constructor then create the AwsS3 driver from environment variables
3136
*
@@ -65,6 +70,7 @@ public function __construct(ModuleContainer $moduleContainer, ?array $config = n
6570
$s3Driver = new AwsS3($adapter, new MockTestLogger(), $objectUrl, $metadataProvider);
6671

6772
$this->driver = $s3Driver;
73+
$this->adapter = $adapter;
6874
}
6975

7076
/**
@@ -196,10 +202,11 @@ public function assertGlobbedFileExists($path, $pattern, $message = ''): void
196202
* @return void
197203
*
198204
* @throws \Magento\Framework\Exception\FileSystemException
205+
* @throws \League\Flysystem\FilesystemException
199206
*/
200207
public function assertDirectoryExists($path, $message = ''): void
201208
{
202-
$this->assertTrue($this->driver->isDirectory($path), "Failed asserting $path exists. " . $message);
209+
$this->assertTrue($this->adapter->directoryExists($path), "Failed asserting $path exists. " . $message);
203210
}
204211

205212
/**

app/code/Magento/AwsS3/Test/Unit/Driver/AwsS3Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ public function testSearchDirectory(): void
439439
$this->metadataProviderMock->expects(self::any())->method('getMetadata')
440440
->willReturnMap([
441441
['path', ['type' => AwsS3::TYPE_DIR]],
442-
['path/1', ['type' => AwsS3::TYPE_FILE]],
443-
['path/2', ['type' => AwsS3::TYPE_FILE]],
442+
['path/1', ['type' => AwsS3::TYPE_DIR]],
443+
['path/2', ['type' => AwsS3::TYPE_DIR]],
444444
]);
445445
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')
446446
->willReturn(new \ArrayIterator($subPaths));

app/code/Magento/RemoteStorage/Driver/Adapter/Cache/CacheInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,12 @@ public function updateMetadata(string $path, array $objectMetadata, bool $persis
9393
* @param string $path
9494
*/
9595
public function storeFileNotExists(string $path): void;
96+
97+
/**
98+
* Store flag that dir path does not exist
99+
*
100+
* @param string $path
101+
* @return void
102+
*/
103+
public function storeDirNotExists(string $path): void;
96104
}

app/code/Magento/RemoteStorage/Driver/Adapter/Cache/Generic.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ public function storeFileNotExists(string $path): void
117117
);
118118
}
119119

120+
/**
121+
* @inheritdoc
122+
*/
123+
public function storeDirNotExists(string $path): void
124+
{
125+
$object = [
126+
'type' => 'dir',
127+
'path' => $path,
128+
];
129+
$this->cacheData[$path] = $object;
130+
$this->cacheAdapter->save(
131+
$this->serializer->serialize([$path => $this->cacheData[$path]]),
132+
$this->prefix . $path,
133+
[self::CACHE_TAG]
134+
);
135+
}
136+
120137
/**
121138
* @inheritdoc
122139
*/

app/code/Magento/RemoteStorage/Driver/Adapter/CachedAdapter.php

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(
5050
}
5151

5252
/**
53-
* {@inheritdoc}
53+
* @inheritdoc
5454
*/
5555
public function write(string $path, string $contents, Config $config): void
5656
{
@@ -63,7 +63,7 @@ public function write(string $path, string $contents, Config $config): void
6363
}
6464

6565
/**
66-
* {@inheritdoc}
66+
* @inheritdoc
6767
*/
6868
public function writeStream(string $path, $contents, Config $config): void
6969
{
@@ -76,7 +76,7 @@ public function writeStream(string $path, $contents, Config $config): void
7676
}
7777

7878
/**
79-
* {@inheritdoc}
79+
* @inheritdoc
8080
*/
8181
public function move(string $source, string $destination, Config $config): void
8282
{
@@ -85,7 +85,7 @@ public function move(string $source, string $destination, Config $config): void
8585
}
8686

8787
/**
88-
* {@inheritdoc}
88+
* @inheritdoc
8989
*/
9090
public function copy(string $source, string $destination, Config $config): void
9191
{
@@ -94,7 +94,7 @@ public function copy(string $source, string $destination, Config $config): void
9494
}
9595

9696
/**
97-
* {@inheritdoc}
97+
* @inheritdoc
9898
*/
9999
public function delete(string $path): void
100100
{
@@ -103,7 +103,7 @@ public function delete(string $path): void
103103
}
104104

105105
/**
106-
* {@inheritdoc}
106+
* @inheritdoc
107107
*/
108108
public function deleteDirectory(string $path): void
109109
{
@@ -112,7 +112,7 @@ public function deleteDirectory(string $path): void
112112
}
113113

114114
/**
115-
* {@inheritdoc}
115+
* @inheritdoc
116116
*/
117117
public function createDirectory(string $path, Config $config): void
118118
{
@@ -123,7 +123,7 @@ public function createDirectory(string $path, Config $config): void
123123
}
124124

125125
/**
126-
* {@inheritdoc}
126+
* @inheritdoc
127127
*/
128128
public function setVisibility(string $path, string $visibility): void
129129
{
@@ -132,7 +132,7 @@ public function setVisibility(string $path, string $visibility): void
132132
}
133133

134134
/**
135-
* {@inheritdoc}
135+
* @inheritdoc
136136
*/
137137
public function fileExists(string $path): bool
138138
{
@@ -165,31 +165,64 @@ public function fileExists(string $path): bool
165165
}
166166

167167
/**
168-
* {@inheritdoc}
168+
* @inheritdoc
169+
*/
170+
public function directoryExists(string $path): bool
171+
{
172+
$cacheHas = $this->cache->exists($path);
173+
174+
if ($cacheHas !== null) {
175+
return $cacheHas;
176+
}
177+
178+
$exists = $this->adapter->directoryExists($path);
179+
180+
if (!$exists) {
181+
try {
182+
// check if target is a directory
183+
$exists = iterator_count($this->adapter->listContents($path, false)) > 0;
184+
} catch (\Throwable $e) {
185+
// catch closed iterator
186+
$exists = false;
187+
}
188+
}
189+
190+
if ($exists) {
191+
$cacheEntry = ['type' => 'dir', 'path' => $path];
192+
$this->cache->updateMetadata($path, $cacheEntry, true);
193+
} else {
194+
$this->cache->storeDirNotExists($path);
195+
}
196+
197+
return $exists;
198+
}
199+
200+
/**
201+
* @inheritdoc
169202
*/
170203
public function read(string $path): string
171204
{
172205
return $this->adapter->read($path);
173206
}
174207

175208
/**
176-
* {@inheritdoc}
209+
* @inheritdoc
177210
*/
178211
public function readStream(string $path)
179212
{
180213
return $this->adapter->readStream($path);
181214
}
182215

183216
/**
184-
* {@inheritdoc}
217+
* @inheritdoc
185218
*/
186219
public function listContents(string $path, bool $deep): iterable
187220
{
188221
return $this->adapter->listContents($path, $deep);
189222
}
190223

191224
/**
192-
* {@inheritdoc}
225+
* @inheritdoc
193226
*/
194227
public function fileSize(string $path): FileAttributes
195228
{
@@ -198,7 +231,7 @@ public function fileSize(string $path): FileAttributes
198231
}
199232

200233
/**
201-
* {@inheritdoc}
234+
* @inheritdoc
202235
*/
203236
public function mimeType(string $path): FileAttributes
204237
{
@@ -207,7 +240,7 @@ public function mimeType(string $path): FileAttributes
207240
}
208241

209242
/**
210-
* {@inheritdoc}
243+
* @inheritdoc
211244
*/
212245
public function lastModified(string $path): FileAttributes
213246
{
@@ -216,7 +249,7 @@ public function lastModified(string $path): FileAttributes
216249
}
217250

218251
/**
219-
* {@inheritdoc}
252+
* @inheritdoc
220253
*/
221254
public function visibility(string $path): FileAttributes
222255
{

app/code/Magento/RemoteStorage/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"require": {
55
"php": "~8.1.0||~8.2.0||~8.3.0",
66
"magento/framework": "*",
7-
"league/flysystem": "^2.4",
8-
"league/flysystem-aws-s3-v3": "^2.4"
7+
"league/flysystem": "^3.0",
8+
"league/flysystem-aws-s3-v3": "^3.0"
99
},
1010
"suggest": {
1111
"magento/module-backend": "*",

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"laminas/laminas-stdlib": "^3.11",
6767
"laminas/laminas-uri": "^2.9",
6868
"laminas/laminas-validator": "^2.23",
69-
"league/flysystem": "^2.4",
70-
"league/flysystem-aws-s3-v3": "^2.4",
69+
"league/flysystem": "^3.0",
70+
"league/flysystem-aws-s3-v3": "^3.0",
7171
"magento/composer": "^1.10.0-beta1",
7272
"magento/composer-dependency-version-audit-plugin": "^0.1",
7373
"magento/magento-composer-installer": ">=0.4.0",

0 commit comments

Comments
 (0)