@@ -86,15 +86,11 @@ public function __construct($params) {
8686 if (isset ($ params ['validateWrites ' ])) {
8787 $ this ->validateWrites = (bool )$ params ['validateWrites ' ];
8888 }
89- //initialize cache with root directory in cache
90- if (!$ this ->is_dir ('/ ' )) {
91- $ this ->mkdir ('/ ' );
92- }
9389
9490 $ this ->logger = \OC ::$ server ->getLogger ();
9591 }
9692
97- public function mkdir ($ path ) {
93+ public function mkdir ($ path, bool $ force = false ) {
9894 $ path = $ this ->normalizePath ($ path );
9995 if ($ this ->file_exists ($ path )) {
10096 return false ;
@@ -240,6 +236,13 @@ public function stat($path) {
240236 if ($ cacheEntry instanceof CacheEntry) {
241237 return $ cacheEntry ->getData ();
242238 } else {
239+ if ($ path === '' ) {
240+ $ this ->mkdir ('' , true );
241+ $ cacheEntry = $ this ->getCache ()->get ($ path );
242+ if ($ cacheEntry instanceof CacheEntry) {
243+ return $ cacheEntry ->getData ();
244+ }
245+ }
243246 return false ;
244247 }
245248 }
@@ -351,6 +354,12 @@ public function fopen($path, $mode) {
351354 case 'wb ' :
352355 case 'w+ ' :
353356 case 'wb+ ' :
357+ $ dirName = dirname ($ path );
358+ $ parentExists = $ this ->is_dir ($ dirName );
359+ if (!$ parentExists ) {
360+ return false ;
361+ }
362+
354363 $ tmpFile = \OC ::$ server ->getTempManager ()->getTemporaryFile ($ ext );
355364 $ handle = fopen ($ tmpFile , $ mode );
356365 return CallbackWrapper::wrap ($ handle , null , null , function () use ($ path , $ tmpFile ) {
@@ -463,6 +472,9 @@ public function needsPartFile() {
463472
464473 public function file_put_contents ($ path , $ data ) {
465474 $ handle = $ this ->fopen ($ path , 'w+ ' );
475+ if (!$ handle ) {
476+ return false ;
477+ }
466478 $ result = fwrite ($ handle , $ data );
467479 fclose ($ handle );
468480 return $ result ;
0 commit comments