move some stuff to the new api

This commit is contained in:
Robin Appelman 2012-10-26 23:05:02 +02:00
parent 4b616764e8
commit 6db81afab9
20 changed files with 58 additions and 45 deletions

View File

@ -32,7 +32,7 @@ if($doBreadcrumb) {
// make filelist // make filelist
$files = array(); $files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] ); $i["date"] = OCP\Util::formatDate($i["mtime"] );
$files[] = $i; $files[] = $i;
} }

View File

@ -65,9 +65,9 @@ if($source) {
$target=$dir.'/'.$filename; $target=$dir.'/'.$filename;
$result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream); $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
if($result) { if($result) {
$meta = OC_FileCache::get($target); $meta = \OC\Files\Filesystem::getFileInfo($target);
$mime=$meta['mimetype']; $mime=$meta['mimetype'];
$id = OC_FileCache::getId($target); $id = $meta['fileid'];
$eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id)); $eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id));
} else { } else {
$eventSource->send('error', "Error while downloading ".$source. ' to '.$target); $eventSource->send('error', "Error while downloading ".$source. ' to '.$target);
@ -77,14 +77,14 @@ if($source) {
} else { } else {
if($content) { if($content) {
if(\OC\Files\Filesystem::file_put_contents($dir.'/'.$filename, $content)) { if(\OC\Files\Filesystem::file_put_contents($dir.'/'.$filename, $content)) {
$meta = OC_FileCache::get($dir.'/'.$filename); $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
$id = OC_FileCache::getId($dir.'/'.$filename); $id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id))); OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit(); exit();
} }
}elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) { }elseif(\OC\Files\Filesystem::touch($dir . '/' . $filename)) {
$meta = OC_FileCache::get($dir.'/'.$filename); $meta = \OC\Files\Filesystem::getFileInfo($dir.'/'.$filename);
$id = OC_FileCache::getId($dir.'/'.$filename); $id = $meta['fileid'];
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id))); OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit(); exit();
} }

View File

@ -25,7 +25,8 @@ if(\OC\Files\Filesystem::mkdir($dir . '/' . stripslashes($foldername))) {
} else { } else {
$path = '/'.$foldername; $path = '/'.$foldername;
} }
$id = OC_FileCache::getId($path); $meta = \OC\Files\Filesystem::getFileInfo($path);
$id = $meta['fileid'];
OCP\JSON::success(array("data" => array('id'=>$id))); OCP\JSON::success(array("data" => array('id'=>$id)));
exit(); exit();
} }

View File

@ -15,7 +15,7 @@ $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
// make filelist // make filelist
$files = array(); $files = array();
foreach( OC_Files::getdirectorycontent( $dir, $mimetype ) as $i ) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] ); $i["date"] = OCP\Util::formatDate($i["mtime"] );
$i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']);
$files[] = $i; $files[] = $i;

View File

@ -49,7 +49,7 @@ if(strpos($dir, '..') === false) {
for($i=0;$i<$fileCount;$i++) { for($i=0;$i<$fileCount;$i++) {
$target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
if(is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { if(is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
$meta = \OC_Files::getFileInfo($target); $meta = \OC\Files\Filesystem::getFileInfo($target);
$id = $meta['fileid']; $id = $meta['fileid'];
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target)); $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target));
} }

View File

@ -44,7 +44,7 @@ if(!\OC\Files\Filesystem::is_dir($dir.'/')) {
} }
$files = array(); $files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i['date'] = OCP\Util::formatDate($i['mtime'] ); $i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file') { if($i['type']=='file') {
$fileinfo=pathinfo($i['name']); $fileinfo=pathinfo($i['name']);

View File

@ -36,7 +36,7 @@ OCP\Util::addscript( "files", "files" );
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$files = array(); $files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] ); $i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] );
$files[] = $i; $files[] = $i;
} }

View File

@ -167,7 +167,7 @@ class OC_CryptStream{
public function stream_close() { public function stream_close() {
$this->flush(); $this->flush();
if($this->meta['mode']!='r' and $this->meta['mode']!='rb') { if($this->meta['mode']!='r' and $this->meta['mode']!='rb') {
OC_FileCache::put($this->path, array('encrypted'=>true,'size'=>$this->size),''); \OC\Files\Filesystem::putFileInfo($this->path, array('encrypted'=>true,'size'=>$this->size),'');
} }
return fclose($this->source); return fclose($this->source);
} }

View File

@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @return bool * @return bool
*/ */
private static function isEncrypted($path) { private static function isEncrypted($path) {
$metadata=OC_FileCache_Cached::get($path,''); $metadata=\OC\Files\Filesystem::getFileInfo($path,'');
return isset($metadata['encrypted']) and (bool)$metadata['encrypted']; return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
} }
@ -68,14 +68,14 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (!is_resource($data)) {//stream put contents should have been converter to fopen if (!is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($data); $size=strlen($data);
$data=OC_Crypt::blockEncrypt($data); $data=OC_Crypt::blockEncrypt($data);
OC_FileCache::put($path, array('encrypted'=>true,'size'=>$size),''); \OC\Files\Filesystem::putFileInfo($path, array('encrypted'=>true,'size'=>$size),'');
} }
} }
} }
public function postFile_get_contents($path,$data) { public function postFile_get_contents($path,$data) {
if(self::isEncrypted($path)) { if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,''); $cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data=OC_Crypt::blockDecrypt($data,'',$cached['size']); $data=OC_Crypt::blockDecrypt($data,'',$cached['size']);
} }
return $data; return $data;
@ -113,7 +113,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postStat($path,$data) { public function postStat($path,$data) {
if(self::isEncrypted($path)) { if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,''); $cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data['size']=$cached['size']; $data['size']=$cached['size'];
} }
return $data; return $data;
@ -121,7 +121,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postFileSize($path,$size) { public function postFileSize($path,$size) {
if(self::isEncrypted($path)) { if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,''); $cached=\OC\Files\Filesystem::getFileInfo($path,'');
return $cached['size']; return $cached['size'];
}else{ }else{
return $size; return $size;

View File

@ -10,6 +10,7 @@ if (version_compare($installedVersion, '0.3', '<')) {
OC_Group::useBackend(new OC_Group_Database()); OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication')); OC_App::loadApps(array('authentication'));
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {
$meta = \OC\Files\Filesystem::getId($path, '');
$itemSource = OC_FileCache::getId($row['source'], ''); $itemSource = OC_FileCache::getId($row['source'], '');
if ($itemSource != -1) { if ($itemSource != -1) {
$file = OC_FileCache::get($row['source'], ''); $file = OC_FileCache::get($row['source'], '');
@ -70,4 +71,4 @@ if (version_compare($installedVersion, '0.3.3', '<')) {
foreach ($users as $user) { foreach ($users as $user) {
OC_FileCache::delete('Shared', '/'.$user.'/files/'); OC_FileCache::delete('Shared', '/'.$user.'/files/');
} }
} }

View File

@ -93,7 +93,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
$path = $this->path . '/' . $name; $path = $this->path . '/' . $name;
if (is_null($info)) { if (is_null($info)) {
$info = OC_Files::getFileInfo($path); $info = \OC\Files\Filesystem::getFileInfo($path);
} }
if (!$info) { if (!$info) {
@ -117,7 +117,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/ */
public function getChildren() { public function getChildren() {
$folder_content = OC_Files::getDirectoryContent($this->path); $folder_content = \OC\Files\Filesystem::getDirectoryContent($this->path);
$paths = array(); $paths = array();
foreach($folder_content as $info) { foreach($folder_content as $info) {
$paths[] = $this->path.'/'.$info['name']; $paths[] = $this->path.'/'.$info['name'];
@ -178,7 +178,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* @return array * @return array
*/ */
public function getQuotaInfo() { public function getQuotaInfo() {
$rootInfo=OC_FileCache_Cached::get(''); $rootInfo=\OC\Files\Filesystem::getFileInfo('');
return array( return array(
$rootInfo['size'], $rootInfo['size'],
\OC\Files\Filesystem::free_space() \OC\Files\Filesystem::free_space()

View File

@ -95,11 +95,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
} }
/** /**
* Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat * Make sure the fileinfo cache is filled. Uses the file cache or a direct stat
*/ */
protected function getFileinfoCache() { protected function getFileinfoCache() {
if (!isset($this->fileinfo_cache)) { if (!isset($this->fileinfo_cache)) {
if ($fileinfo_cache = \OC\Files\Filesystem::get($this->path)) { if ($fileinfo_cache = \OC\Files\Filesystem::getFileInfo($this->path)) {
} else { } else {
$fileinfo_cache = \OC\Files\Filesystem::stat($this->path); $fileinfo_cache = \OC\Files\Filesystem::stat($this->path);
} }

View File

@ -57,7 +57,7 @@ class OC_FileProxy_Quota extends OC_FileProxy{
* @return int * @return int
*/ */
private function getFreeSpace($path) { private function getFreeSpace($path) {
$storage=OC_Filesystem::getStorage($path); list($storage,)=\OC\Files\Filesystem::resolvePath($path);
$owner=$storage->getOwner($path); $owner=$storage->getOwner($path);
$totalSpace=$this->getQuota($owner); $totalSpace=$this->getQuota($owner);
@ -65,13 +65,9 @@ class OC_FileProxy_Quota extends OC_FileProxy{
return 0; return 0;
} }
$rootInfo=OC_FileCache::get('', "/".$owner."/files"); $view = new \OC\Files\View("/".$owner."/files");
// TODO Remove after merge of share_api
if (OC_FileCache::inCache('/Shared', "/".$owner."/files")) { $rootInfo=$view->getFileInfo('/');
$sharedInfo=OC_FileCache::get('/Shared', "/".$owner."/files");
} else {
$sharedInfo = null;
}
$usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0; $usedSpace=isset($rootInfo['size'])?$rootInfo['size']:0;
$usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace; $usedSpace=isset($sharedInfo['size'])?$usedSpace-$sharedInfo['size']:$usedSpace;
return $totalSpace-$usedSpace; return $totalSpace-$usedSpace;

View File

@ -146,7 +146,7 @@ class OC_Files {
$dirname = basename($dir); $dirname = basename($dir);
$zip->addEmptyDir($internalDir . $dirname); $zip->addEmptyDir($internalDir . $dirname);
$internalDir .= $dirname .= '/'; $internalDir .= $dirname .= '/';
$files = OC_Files::getdirectorycontent($dir); $files = \OC\Files\Filesystem::getDirectoryContent($dir);
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file['name']; $filename = $file['name'];
$file = $dir . '/' . $filename; $file = $dir . '/' . $filename;

View File

@ -627,6 +627,19 @@ class Filesystem {
return self::$defaultInstance->getFileInfo($path); return self::$defaultInstance->getFileInfo($path);
} }
/**
* change file metadata
*
* @param string $path
* @param array $data
* @return int
*
* returns the fileid of the updated file
*/
public static function putFileInfo($path, $data) {
return self::$defaultInstance->putFileInfo($path, $data);
}
/** /**
* get the content of a directory * get the content of a directory
* *

View File

@ -451,7 +451,6 @@ class View {
array(Filesystem::signal_param_path => $path2) array(Filesystem::signal_param_path => $path2)
); );
} else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions } else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions
// OC_FileCache_Update::update($path2, $this->fakeRoot);
Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot); Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
} }
return $result; return $result;

View File

@ -590,8 +590,8 @@ class OC_OCS {
// calculate the disc space // calculate the disc space
$user_dir = '/'.$user.'/files'; $user_dir = '/'.$user.'/files';
\OC\Files\Filesystem::init($user_dir); \OC\Files\Filesystem::init($user_dir);
$rootInfo=OC_FileCache::get(''); $rootInfo=\OC\Files\Filesystem::getFileInfo('');
$sharedInfo=OC_FileCache::get('/Shared'); $sharedInfo=\OC\Files\Filesystem::getFileInfo('/Shared');
$used=$rootInfo['size']-$sharedInfo['size']; $used=$rootInfo['size']-$sharedInfo['size'];
$free=\OC\Files\Filesystem::free_space(); $free=\OC\Files\Filesystem::free_space();
$total=$free+$used; $total=$free+$used;

View File

@ -285,10 +285,10 @@ class Share {
// If the item is a folder, scan through the folder looking for equivalent item types // If the item is a folder, scan through the folder looking for equivalent item types
if ($itemType == 'folder') { if ($itemType == 'folder') {
$parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true); $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true);
if ($parentFolder && $files = \OC_Files::getDirectoryContent($itemSource)) { if ($parentFolder && $files = \OC\Files\Filesystem::getDirectoryContent($itemSource)) {
for ($i = 0; $i < count($files); $i++) { for ($i = 0; $i < count($files); $i++) {
$name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource)); $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource));
if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC_Files::getDirectoryContent($name, '/')) { if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC\Files\Filesystem::getDirectoryContent($name, '/')) {
// Continue scanning into child folders // Continue scanning into child folders
array_push($files, $children); array_push($files, $children);
} else { } else {
@ -768,9 +768,10 @@ class Share {
if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') { if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
$childItem['file_source'] = $child['source']; $childItem['file_source'] = $child['source'];
} else { } else {
$childItem['file_source'] = \OC_FileCache::getId($child['file_path']); $meta = \OC\Files\Filesystem::getFileInfo($child['file_path']);
$childItem['file_source'] = $meta['fileid'];
} }
$childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']); $childItem['file_target'] = \OC\Files\Filesystem::normalizePath($child['file_path']);
} }
if (isset($item)) { if (isset($item)) {
if ($childItem[$column] == $item) { if ($childItem[$column] == $item) {
@ -881,7 +882,8 @@ class Share {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$fileSource = $itemSource; $fileSource = $itemSource;
} else { } else {
$fileSource = \OC_FileCache::getId($filePath); $meta = \OC\Files\Filesystem::getFileInfo($filePath);
$fileSource = $meta['fileid'];
} }
if ($fileSource == -1) { if ($fileSource == -1) {
$message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache'; $message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache';
@ -1063,7 +1065,8 @@ class Share {
} }
if ($item['uid_owner'] == $uidOwner) { if ($item['uid_owner'] == $uidOwner) {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
if ($item['file_source'] == \OC_FileCache::getId($itemSource)) { $meta = \OC\Files\Filesystem::getFileInfo($itemSource);
if ($item['file_source'] == $meta['fileid']) {
return $target; return $target;
} }
} else if ($item['item_source'] == $itemSource) { } else if ($item['item_source'] == $itemSource) {

View File

@ -2,7 +2,7 @@
class OC_Search_Provider_File extends OC_Search_Provider{ class OC_Search_Provider_File extends OC_Search_Provider{
function search($query) { function search($query) {
$files=OC_FileCache::search($query, true); $files=\OC\Files\Filesystem::search($query, true);
$results=array(); $results=array();
$l=OC_L10N::get('lib'); $l=OC_L10N::get('lib');
foreach($files as $fileData) { foreach($files as $fileData) {

View File

@ -16,8 +16,8 @@ OC_Util::addStyle( '3rdparty', 'chosen' );
OC_App::setActiveNavigationEntry( 'personal' ); OC_App::setActiveNavigationEntry( 'personal' );
// calculate the disc space // calculate the disc space
$rootInfo=OC_FileCache::get(''); $rootInfo=\OC\Files\Filesystem::getFileInfo('');
$sharedInfo=OC_FileCache::get('/Shared'); $sharedInfo=\OC\Files\Filesystem::getFileInfo('/Shared');
$used=$rootInfo['size']; $used=$rootInfo['size'];
if($used<0) $used=0; if($used<0) $used=0;
$free=\OC\Files\Filesystem::free_space(); $free=\OC\Files\Filesystem::free_space();