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
445445
446446 $ path = $ this ->normalizeRelativePath ($ path , true );
447447
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 );
458449 }
459450
460451 /**
461452 * Check is given path a directory in metadata.
462453 *
463454 * @param string $path
464455 * @return bool
465- * @throws UnableToRetrieveMetadata
466456 */
467457 private function isTypeDirectory ($ path )
468458 {
469- $ meta = $ this ->metadataProvider ->getMetadata ($ path );
459+ try {
460+ $ meta = $ this ->metadataProvider ->getMetadata ($ path );
461+ } catch (UnableToRetrieveMetadata $ e ) {
462+ return false ;
463+ }
470464 if (isset ($ meta ['type ' ]) && $ meta ['type ' ] === self ::TYPE_DIR ) {
471465 return true ;
472466 }
Original file line number Diff line number Diff line change @@ -188,9 +188,18 @@ public function getMetadata(string $path): ?array
188188 {
189189 if (isset ($ this ->cacheData [$ path ]['type ' ])) {
190190 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 ];
191202 }
192-
193- return null ;
194203 }
195204
196205 /**
Original file line number Diff line number Diff line change @@ -41,6 +41,22 @@ public function __construct(
4141 $ this ->cache = $ cache ;
4242 }
4343
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+
4460 /**
4561 * @inheritdoc
4662 */
@@ -54,6 +70,27 @@ public function getMetadata(string $path): array
5470 }
5571 try {
5672 $ 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+ }
5794 } catch (\InvalidArgumentException | FilesystemException $ e ) {
5895 throw new UnableToRetrieveMetadata (
5996 "Unable to retrieve metadata for file at location: {$ path }. {$ e ->getMessage ()}" ,
You can’t perform that action at this time.
0 commit comments