@@ -66,6 +66,29 @@ public function setFileInfo(IStorage $storage, string $path) {
6666 }
6767 }
6868
69+ /**
70+ * The mimetype is only cached if the file exists. Otherwise files access
71+ * control will cache "application/octet-stream" for all the target node on:
72+ * rename, move, copy and all other methods which create a new item
73+ *
74+ * To check this:
75+ * 1. Add an automated tagging rule which tags on mimetype NOT "httpd/unix-directory"
76+ * 2. Add an access control rule which checks for any mimetype
77+ * 3. Create a folder and rename it, the folder should not be tagged, but it is
78+ *
79+ * @param string $storageId
80+ * @param string|null $path
81+ * @param string $mimeType
82+ * @return string
83+ */
84+ protected function cacheAndReturnMimeType (string $ storageId , ?string $ path , string $ mimeType ): string {
85+ if ($ path !== null && $ this ->storage ->file_exists ($ path )) {
86+ $ this ->mimeType [$ storageId ][$ path ] = $ mimeType ;
87+ }
88+
89+ return $ mimeType ;
90+ }
91+
6992 /**
7093 * @return string
7194 */
@@ -75,25 +98,23 @@ protected function getActualValue() {
7598 }
7699
77100 if ($ this ->storage ->is_dir ($ this ->path )) {
78- $ this ->mimeType [$ this ->storage ->getId ()][$ this ->path ] = 'httpd/unix-directory ' ;
79- return $ this ->mimeType [$ this ->storage ->getId ()][$ this ->path ];
101+ return $ this ->cacheAndReturnMimeType ($ this ->storage ->getId (), $ this ->path , 'httpd/unix-directory ' );
80102 }
81103
82104 if ($ this ->isWebDAVRequest ()) {
83105 // Creating a folder
84106 if ($ this ->request ->getMethod () === 'MKCOL ' ) {
85- $ this ->mimeType [$ this ->storage ->getId ()][$ this ->path ] = 'httpd/unix-directory ' ;
86- return $ this ->mimeType [$ this ->storage ->getId ()][$ this ->path ];
107+ return $ this ->cacheAndReturnMimeType ($ this ->storage ->getId (), $ this ->path , 'httpd/unix-directory ' );
87108 }
88109
89110 if ($ this ->request ->getMethod () === 'PUT ' || $ this ->request ->getMethod () === 'MOVE ' ) {
90111 if ($ this ->request ->getMethod () === 'MOVE ' ) {
91- $ this -> mimeType [ $ this -> storage -> getId ()][ $ this -> path ] = $ this ->mimeTypeDetector ->detectPath ($ this ->path );
112+ $ mimeType = $ this ->mimeTypeDetector ->detectPath ($ this ->path );
92113 } else {
93114 $ path = $ this ->request ->getPathInfo ();
94- $ this -> mimeType [ $ this -> storage -> getId ()][ $ this -> path ] = $ this ->mimeTypeDetector ->detectPath ($ path );
115+ $ mimeType = $ this ->mimeTypeDetector ->detectPath ($ path );
95116 }
96- return $ this ->mimeType [ $ this ->storage ->getId ()][ $ this ->path ] ;
117+ return $ this ->cacheAndReturnMimeType ( $ this ->storage ->getId (), $ this ->path , $ mimeType ) ;
97118 }
98119 } else if ($ this ->isPublicWebDAVRequest ()) {
99120 if ($ this ->request ->getMethod () === 'PUT ' ) {
@@ -102,8 +123,8 @@ protected function getActualValue() {
102123 $ path = substr ($ path , strlen ('/webdav ' ));
103124 }
104125 $ path = $ this ->path . $ path ;
105- $ this -> mimeType [ $ this -> storage -> getId ()][ $ path ] = $ this ->mimeTypeDetector ->detectPath ($ path );
106- return $ this ->mimeType [ $ this ->storage ->getId ()][ $ path] ;
126+ $ mimeType = $ this ->mimeTypeDetector ->detectPath ($ path );
127+ return $ this ->cacheAndReturnMimeType ( $ this ->storage ->getId (), $ path, $ mimeType ) ;
107128 }
108129 }
109130
@@ -123,17 +144,16 @@ protected function getActualValue() {
123144 }
124145 }
125146 }
126- $ this ->mimeType [$ this ->storage ->getId ()][$ this ->path ] = $ mimeType ;
127- return $ mimeType ;
147+ return $ this ->cacheAndReturnMimeType ($ this ->storage ->getId (), $ this ->path , $ mimeType );
128148 }
129149 }
130150
131- $ this -> mimeType [ $ this -> storage -> getId ()][ $ this -> path ] = $ this ->storage ->getMimeType ($ this ->path );
132- if ($ this -> mimeType [ $ this -> storage -> getId ()][ $ this -> path ] === 'application/octet-stream ' ) {
133- $ this -> mimeType [ $ this -> storage -> getId ()][ $ this -> path ] = $ this ->detectMimetypeFromPath ();
151+ $ mimeType = $ this ->storage ->getMimeType ($ this ->path );
152+ if ($ mimeType === 'application/octet-stream ' ) {
153+ $ mimeType = $ this ->detectMimetypeFromPath ();
134154 }
135155
136- return $ this ->mimeType [ $ this ->storage ->getId ()][ $ this ->path ] ;
156+ return $ this ->cacheAndReturnMimeType ( $ this ->storage ->getId (), $ this ->path , $ mimeType ) ;
137157 }
138158
139159 /**
0 commit comments