File tree Expand file tree Collapse file tree 3 files changed +54
-14
lines changed
RemoteStorage/Driver/Adapter Expand file tree Collapse file tree 3 files changed +54
-14
lines changed Original file line number Diff line number Diff line change @@ -445,28 +445,22 @@ public function isDirectory($path): bool
445
445
446
446
$ path = $ this ->normalizeRelativePath ($ path , true );
447
447
448
- try {
449
- return $ this ->isTypeDirectory ($ path );
450
- } catch (UnableToRetrieveMetadata $ e ) {
451
- try {
452
- return iterator_count ($ this ->adapter ->listContents ($ path , false )) > 0 ;
453
- } catch (\Throwable $ e ) {
454
- // catch closed iterator
455
- return false ;
456
- }
457
- }
448
+ return $ this ->isTypeDirectory ($ path );
458
449
}
459
450
460
451
/**
461
452
* Check is given path a directory in metadata.
462
453
*
463
454
* @param string $path
464
455
* @return bool
465
- * @throws UnableToRetrieveMetadata
466
456
*/
467
457
private function isTypeDirectory ($ path )
468
458
{
469
- $ meta = $ this ->metadataProvider ->getMetadata ($ path );
459
+ try {
460
+ $ meta = $ this ->metadataProvider ->getMetadata ($ path );
461
+ } catch (UnableToRetrieveMetadata $ e ) {
462
+ return false ;
463
+ }
470
464
if (isset ($ meta ['type ' ]) && $ meta ['type ' ] === self ::TYPE_DIR ) {
471
465
return true ;
472
466
}
Original file line number Diff line number Diff line change @@ -188,9 +188,18 @@ public function getMetadata(string $path): ?array
188
188
{
189
189
if (isset ($ this ->cacheData [$ path ]['type ' ])) {
190
190
return $ this ->cacheData [$ path ];
191
+ } else {
192
+ $ meta = $ this ->cacheAdapter ->load ($ this ->prefix . $ path );
193
+ if (!$ meta ) {
194
+ return null ;
195
+ }
196
+ $ meta = $ this ->serializer ->unserialize ($ meta );
197
+ if (!$ meta [$ path ]) {
198
+ return null ;
199
+ }
200
+ $ this ->cacheData [$ path ] = $ meta [$ path ];
201
+ return $ this ->cacheData [$ path ];
191
202
}
192
-
193
- return null ;
194
203
}
195
204
196
205
/**
Original file line number Diff line number Diff line change @@ -41,6 +41,22 @@ public function __construct(
41
41
$ this ->cache = $ cache ;
42
42
}
43
43
44
+ /**
45
+ * Check is the given path an existing directory.
46
+ *
47
+ * @param string $path
48
+ * @return bool
49
+ */
50
+ private function isDirectory ($ path ): bool
51
+ {
52
+ try {
53
+ return iterator_count ($ this ->adapter ->listContents ($ path , false )) > 0 ;
54
+ } catch (\Throwable $ e ) {
55
+ // catch closed iterator
56
+ return false ;
57
+ }
58
+ }
59
+
44
60
/**
45
61
* @inheritdoc
46
62
*/
@@ -54,6 +70,27 @@ public function getMetadata(string $path): array
54
70
}
55
71
try {
56
72
$ meta = $ this ->adapter ->lastModified ($ path );
73
+ } catch (UnableToRetrieveMetadata $ e ) {
74
+ if ($ this ->isDirectory ($ path )) {
75
+ $ data = [
76
+ 'path ' => $ path ,
77
+ 'type ' => 'dir ' ,
78
+ 'size ' => null ,
79
+ 'timestamp ' => null ,
80
+ 'visibility ' => null ,
81
+ 'mimetype ' => null ,
82
+ 'dirname ' => dirname ($ path ),
83
+ 'basename ' => basename ($ path ),
84
+ ];
85
+ $ this ->cache ->updateMetadata ($ path , $ data , true );
86
+ return $ data ;
87
+ } else {
88
+ throw new UnableToRetrieveMetadata (
89
+ "Unable to retrieve metadata for file at location: {$ path }. {$ e ->getMessage ()}" ,
90
+ 0 ,
91
+ $ e
92
+ );
93
+ }
57
94
} catch (\InvalidArgumentException | FilesystemException $ e ) {
58
95
throw new UnableToRetrieveMetadata (
59
96
"Unable to retrieve metadata for file at location: {$ path }. {$ e ->getMessage ()}" ,
You can’t perform that action at this time.
0 commit comments