]> source.dussan.org Git - nextcloud-server.git/commitdiff
create correct file cache entries for new files/folder created in shared folders
authorBjörn Schießle <schiessle@owncloud.com>
Tue, 13 Nov 2012 14:32:38 +0000 (15:32 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Tue, 13 Nov 2012 14:32:38 +0000 (15:32 +0100)
apps/files_sharing/lib/sharedstorage.php
lib/filecache.php

index 6dba76955a0af5b09f3b56c8749e7ca580d4a1fa..98f6f3f0e21e9f7d952af5822526b769d85c4286 100644 (file)
@@ -112,8 +112,14 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
                if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
                        return false;
                } else if ($source = $this->getSourcePath($path)) {
+                       $parts = explode('/', $source, 4);
+                       $user =  $parts[1];
+                       $intPath = '/'.$parts[3];
                        $storage = OC_Filesystem::getStorage($source);
-                       return $storage->mkdir($this->getInternalPath($source));
+                       if( ($storage->mkdir($this->getInternalPath($source))) ) {
+                               OC_FileCache::put($intPath ,array('user'=>$user), '/'.$user.'/files');
+                               return true;
+                       }
                }
                return false;
        }
@@ -296,10 +302,15 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
                                        'target' => $this->sharedFolder.$path,
                                        'source' => $source,
                                );
-                       OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
+                       OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);\r
+                       $parts = explode('/', $source, 4);
+                       $user =  $parts[1];
+                       $intPath = '/'.$parts[3];
                        $storage = OC_Filesystem::getStorage($source);
-                       $result = $storage->file_put_contents($this->getInternalPath($source), $data);
-                       return $result;
+                       if( ( $result = $storage->file_put_contents($this->getInternalPath($source), $data) ) ) {
+                               OC_FileCache::put($intPath ,array('user'=>$user), '/'.$user.'/files');
+                               return $result;
+                       }       
                }
                return false;
        }
@@ -368,17 +379,18 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
 
        public function fopen($path, $mode) {
                if ($source = $this->getSourcePath($path)) {
+                       $write = false;
                        switch ($mode) {
+                               case 'w':\r
+                               case 'wb':
+                               case 'w+':\r
+                               case 'wb+': $write = true;
                                case 'r+':
                                case 'rb+':
-                               case 'w+':
-                               case 'wb+':
                                case 'x+':
                                case 'xb+':
                                case 'a+':
                                case 'ab+':
-                               case 'w':
-                               case 'wb':
                                case 'x':
                                case 'xb':
                                case 'a':
@@ -394,7 +406,15 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
                        );
                        OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info);
                        $storage = OC_Filesystem::getStorage($source);
-                       return $storage->fopen($this->getInternalPath($source), $mode);
+                       
+                       $parts = explode('/', $source, 4);
+                       $user =  $parts[1];
+                       $intPath = '/'.$parts[3];\r
+\r
+                       if ( $write && $storage->touch($this->getInternalPath($source)) ) {\r
+                               OC_FileCache::put($intPath ,array('user'=>$user), '/'.$user.'/files');\r
+                               return $storage->fopen($this->getInternalPath($source), $mode);\r
+                       }                       
                }
                return false;
        }
index 9ce94c6f7336e1f244a782496af44a70e1198c5d..40d63021273f3fee13f7c3b582e1f44ed7a769b5 100644 (file)
@@ -79,8 +79,8 @@ class OC_FileCache{
 
                // add parent directory to the file cache if it does not exist yet.
                if ($parent == -1 && $fullpath != $root) {
-                       $parentDir = dirname($path);
-                       self::scanFile($parentDir);
+                       $parentDir = dirname(OC_Filesystem::normalizePath($path));
+                       self::scanFile($parentDir, $root);
                        $parent = self::getParentId($fullpath);
                }
 
@@ -94,15 +94,19 @@ class OC_FileCache{
                if(!isset($data['versioned'])) {
                        $data['versioned']=false;
                }
+               if(!isset($data['user'])) {
+                       $data['user']=OC_User::getUser();
+               }
+               
+               
                $mimePart=dirname($data['mimetype']);
                $data['size']=(int)$data['size'];
                $data['ctime']=(int)$data['mtime'];
                $data['writable']=(int)$data['writable'];
                $data['encrypted']=(int)$data['encrypted'];
                $data['versioned']=(int)$data['versioned'];
-               $user=OC_User::getUser();
                $query=OC_DB::prepare('INSERT INTO `*PREFIX*fscache`(`parent`, `name`, `path`, `path_hash`, `size`, `mtime`, `ctime`, `mimetype`, `mimepart`,`user`,`writable`,`encrypted`,`versioned`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
-               $result=$query->execute(array($parent,basename($fullpath),$fullpath,md5($fullpath),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
+               $result=$query->execute(array($parent,basename($fullpath),$fullpath,md5($fullpath),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$data['user'],$data['writable'],$data['encrypted'],$data['versioned']));
                if(OC_DB::isError($result)) {
                        OC_Log::write('files','error while writing file('.$fullpath.') to cache',OC_Log::ERROR);
                }