Skip to content

Commit 6902f63

Browse files
committed
Merge remote-tracking branch 'gl_magento2ce/AC10721' into AC10721April24
2 parents ef6d9c8 + d2787d3 commit 6902f63

File tree

10 files changed

+186
-58
lines changed

10 files changed

+186
-58
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function __construct(ModuleContainer $moduleContainer, ?array $config = n
6565
$s3Driver = new AwsS3($adapter, new MockTestLogger(), $objectUrl, $metadataProvider);
6666

6767
$this->driver = $s3Driver;
68+
$this->adapter = $adapter;
6869
}
6970

7071
/**
@@ -196,10 +197,11 @@ public function assertGlobbedFileExists($path, $pattern, $message = ''): void
196197
* @return void
197198
*
198199
* @throws \Magento\Framework\Exception\FileSystemException
200+
* @throws \League\Flysystem\FilesystemException
199201
*/
200202
public function assertDirectoryExists($path, $message = ''): void
201203
{
202-
$this->assertTrue($this->driver->isDirectory($path), "Failed asserting $path exists. " . $message);
204+
$this->assertTrue($this->adapter->directoryExists($path), "Failed asserting $path exists. " . $message);
203205
}
204206

205207
/**

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
@@ -107,6 +107,23 @@ public function storeFileNotExists(string $path): void
107107
);
108108
}
109109

110+
/**
111+
* @inheritdoc
112+
*/
113+
public function storeDirNotExists(string $path): void
114+
{
115+
$object = [
116+
'type' => 'dir',
117+
'path' => $path,
118+
];
119+
$this->cacheData[$path] = $object;
120+
$this->cacheAdapter->save(
121+
$this->serializer->serialize([$path => $this->cacheData[$path]]),
122+
$this->prefix . $path,
123+
[self::CACHE_TAG]
124+
);
125+
}
126+
110127
/**
111128
* @inheritdoc
112129
*/

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": "*",

app/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@
18571857
<type name="Magento\Framework\DB\Adapter\SqlVersionProvider">
18581858
<arguments>
18591859
<argument name="supportedVersionPatterns" xsi:type="array">
1860-
<item name="MySQL-8" xsi:type="string">^8\.0\.</item>
1860+
<item name="MySQL-8.1" xsi:type="string">^8\.1\.</item>
18611861
<item name="MySQL-5.7" xsi:type="string">^5\.7\.</item>
18621862
<item name="MariaDB-(10.2-10.6)" xsi:type="string">^10\.[2-6]\.</item>
18631863
</argument>

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)