@@ -87,17 +87,13 @@ public function __construct($params) {
8787 if (isset ($ params ['validateWrites ' ])) {
8888 $ this ->validateWrites = (bool )$ params ['validateWrites ' ];
8989 }
90- //initialize cache with root directory in cache
91- if (!$ this ->is_dir ('/ ' )) {
92- $ this ->mkdir ('/ ' );
93- }
9490
9591 $ this ->logger = \OC ::$ server ->getLogger ();
9692 }
9793
98- public function mkdir ($ path ) {
94+ public function mkdir ($ path, bool $ force = false ) {
9995 $ path = $ this ->normalizePath ($ path );
100- if ($ this ->file_exists ($ path )) {
96+ if (! $ force && $ this ->file_exists ($ path )) {
10197 $ this ->logger ->warning ("Tried to create an object store folder that already exists: $ path " );
10298 return false ;
10399 }
@@ -246,6 +242,13 @@ public function stat($path) {
246242 if ($ cacheEntry instanceof CacheEntry) {
247243 return $ cacheEntry ->getData ();
248244 } else {
245+ if ($ path === '' ) {
246+ $ this ->mkdir ('' , true );
247+ $ cacheEntry = $ this ->getCache ()->get ($ path );
248+ if ($ cacheEntry instanceof CacheEntry) {
249+ return $ cacheEntry ->getData ();
250+ }
251+ }
249252 return false ;
250253 }
251254 }
@@ -357,6 +360,13 @@ public function fopen($path, $mode) {
357360 case 'wb ' :
358361 case 'w+ ' :
359362 case 'wb+ ' :
363+ $ dirName = dirname ($ path );
364+ $ parentExists = $ this ->is_dir ($ dirName );
365+ if (!$ parentExists ) {
366+ throw new \Exception ("parent $ dirName not found in object store " );
367+ return false ;
368+ }
369+
360370 $ tmpFile = \OC ::$ server ->getTempManager ()->getTemporaryFile ($ ext );
361371 $ handle = fopen ($ tmpFile , $ mode );
362372 return CallbackWrapper::wrap ($ handle , null , null , function () use ($ path , $ tmpFile ) {
@@ -469,6 +479,9 @@ public function needsPartFile() {
469479
470480 public function file_put_contents ($ path , $ data ) {
471481 $ handle = $ this ->fopen ($ path , 'w+ ' );
482+ if (!$ handle ) {
483+ return false ;
484+ }
472485 $ result = fwrite ($ handle , $ data );
473486 fclose ($ handle );
474487 return $ result ;
0 commit comments