43
43
44
44
use OC \Files \Filesystem ;
45
45
use OC \Files \Storage \Wrapper \Jail ;
46
+ use OCP \Constants ;
46
47
use OCP \Files \ForbiddenException ;
47
48
use OCP \Files \Storage \IStorage ;
48
49
use OCP \ILogger ;
@@ -111,9 +112,9 @@ public function rmdir($path) {
111
112
if (in_array ($ file ->getBasename (), ['. ' , '.. ' ])) {
112
113
$ it ->next ();
113
114
continue ;
114
- } elseif ($ file ->isDir ()) {
115
+ } else if ($ file ->isDir ()) {
115
116
rmdir ($ file ->getPathname ());
116
- } elseif ($ file ->isFile () || $ file ->isLink ()) {
117
+ } else if ($ file ->isFile () || $ file ->isLink ()) {
117
118
unlink ($ file ->getPathname ());
118
119
}
119
120
$ it ->next ();
@@ -151,6 +152,54 @@ public function stat($path) {
151
152
return $ statResult ;
152
153
}
153
154
155
+ /**
156
+ * @inheritdoc
157
+ */
158
+ public function getMetaData ($ path ) {
159
+ $ fullPath = $ this ->getSourcePath ($ path );
160
+ $ stat = @stat ($ fullPath );
161
+ if (!$ stat ) {
162
+ return null ;
163
+ }
164
+
165
+ $ permissions = Constants::PERMISSION_SHARE ;
166
+ $ statPermissions = $ stat ['mode ' ];
167
+ $ isDir = ($ statPermissions & 0x4000 ) === 0x4000 ;
168
+ if ($ statPermissions & 0x0100 ) {
169
+ $ permissions += Constants::PERMISSION_READ ;
170
+ }
171
+ if ($ statPermissions & 0x0080 ) {
172
+ $ permissions += Constants::PERMISSION_UPDATE ;
173
+ if ($ isDir ) {
174
+ $ permissions += Constants::PERMISSION_CREATE ;
175
+ }
176
+ }
177
+
178
+ if (!($ path === '' || $ path === '/ ' )) { // deletable depends on the parents unix permissions
179
+ $ parent = dirname ($ fullPath );
180
+ if (is_writable ($ parent )) {
181
+ $ permissions += Constants::PERMISSION_DELETE ;
182
+ }
183
+ }
184
+
185
+ $ data = [];
186
+ $ data ['mimetype ' ] = $ isDir ? 'httpd/unix-directory ' : \OC ::$ server ->getMimeTypeDetector ()->detectPath ($ path );
187
+ $ data ['mtime ' ] = $ stat ['mtime ' ];
188
+ if ($ data ['mtime ' ] === false ) {
189
+ $ data ['mtime ' ] = time ();
190
+ }
191
+ if ($ isDir ) {
192
+ $ data ['size ' ] = -1 ; //unknown
193
+ } else {
194
+ $ data ['size ' ] = $ stat ['size ' ];
195
+ }
196
+ $ data ['etag ' ] = $ this ->calculateEtag ($ path , $ stat );
197
+ $ data ['storage_mtime ' ] = $ data ['mtime ' ];
198
+ $ data ['permissions ' ] = $ permissions ;
199
+
200
+ return $ data ;
201
+ }
202
+
154
203
public function filetype ($ path ) {
155
204
$ filetype = filetype ($ this ->getSourcePath ($ path ));
156
205
if ($ filetype == 'link ' ) {
@@ -424,9 +473,13 @@ public function isLocal() {
424
473
* @return string
425
474
*/
426
475
public function getETag ($ path ) {
427
- if ( $ this ->is_file ($ path )) {
428
- $ stat = $ this -> stat ( $ path );
476
+ return $ this -> calculateEtag ( $ path , $ this ->stat ($ path ));
477
+ }
429
478
479
+ private function calculateEtag (string $ path , array $ stat ): string {
480
+ if ($ stat ['mode ' ] & 0x4000 ) { // is_dir
481
+ return parent ::getETag ($ path );
482
+ } else {
430
483
if ($ stat === false ) {
431
484
return md5 ('' );
432
485
}
@@ -446,8 +499,6 @@ public function getETag($path) {
446
499
}
447
500
448
501
return md5 ($ toHash );
449
- } else {
450
- return parent ::getETag ($ path );
451
502
}
452
503
}
453
504
0 commit comments