move the identification of the real path of a shared file to the filecache
This commit is contained in:
parent
cb55229c1e
commit
cb0666e235
|
@ -49,19 +49,8 @@ if(strpos($dir, '..') === false) {
|
|||
for($i=0;$i<$fileCount;$i++) {
|
||||
$target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
|
||||
if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
|
||||
if ( OC_App::isEnabled('files_sharing') && !strncmp($target, '/Shared/', 8)) {
|
||||
$source = OC_Files_Sharing_Util::getSourcePath(str_replace('/Shared/', '', $target));
|
||||
$parts = explode('/', $source, 4);
|
||||
$root = '/'.$parts[1].'/files';
|
||||
$path = '/'.$parts[3];
|
||||
} else {
|
||||
$path = $target;
|
||||
$root = false;
|
||||
}
|
||||
|
||||
$meta = OC_FileCache::get($path, $root);
|
||||
$id = OC_FileCache::getId($path, $root);
|
||||
|
||||
$meta = OC_FileCache::get($target);
|
||||
$id = OC_FileCache::getId($target);
|
||||
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ class OC_FileCache{
|
|||
* - versioned
|
||||
*/
|
||||
public static function get($path,$root=false) {
|
||||
|
||||
list($path, $root) = self::getSourcePathOfSharedFile($path);
|
||||
|
||||
if(OC_FileCache_Update::hasUpdated($path,$root)) {
|
||||
if($root===false) {//filesystem hooks are only valid for the default root
|
||||
OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
|
||||
|
@ -277,6 +280,9 @@ class OC_FileCache{
|
|||
* @return int
|
||||
*/
|
||||
public static function getId($path,$root=false) {
|
||||
|
||||
list($path, $root) = self::getSourcePathOfSharedFile($path);
|
||||
|
||||
if($root===false) {
|
||||
$root=OC_Filesystem::getRoot();
|
||||
}
|
||||
|
@ -507,6 +513,24 @@ class OC_FileCache{
|
|||
$query->execute(array('httpd/unix-directory'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the real path and the root of a shared file
|
||||
* @param string $path
|
||||
* @return array with the path and the root of the give file
|
||||
*/
|
||||
private static function getSourcePathOfSharedFile($path) {
|
||||
if ( OC_App::isEnabled('files_sharing') && !strncmp($path, '/Shared/', 8)) {
|
||||
$source = OC_Files_Sharing_Util::getSourcePath(str_replace('/Shared/', '', $path));
|
||||
$parts = explode('/', $source, 4);
|
||||
$root = '/'.$parts[1].'/files';
|
||||
$path = '/'.$parts[3];
|
||||
} else {
|
||||
$root = false;
|
||||
}
|
||||
|
||||
return array($path, $root);
|
||||
}
|
||||
}
|
||||
|
||||
//watch for changes and try to keep the cache up to date
|
||||
|
|
Loading…
Reference in New Issue