create correct file cache entries for new files/folder created in shared folders

This commit is contained in:
Björn Schießle 2012-11-13 15:32:38 +01:00
parent 39b6bb8a18
commit 781b579074
2 changed files with 37 additions and 13 deletions

View 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);
$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':
case 'wb':
case 'w+':
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];
if ( $write && $storage->touch($this->getInternalPath($source)) ) {
OC_FileCache::put($intPath ,array('user'=>$user), '/'.$user.'/files');
return $storage->fopen($this->getInternalPath($source), $mode);
}
}
return false;
}

View 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);
}