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
$files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] );
$files[] = $i;
}

View File

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

View File

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

View File

@ -15,7 +15,7 @@ $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
// make filelist
$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['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']);
$files[] = $i;

View File

@ -49,7 +49,7 @@ 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\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
$meta = \OC_Files::getFileInfo($target);
$meta = \OC\Files\Filesystem::getFileInfo($target);
$id = $meta['fileid'];
$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();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) {
$i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file') {
$fileinfo=pathinfo($i['name']);

View File

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

View File

@ -167,7 +167,7 @@ class OC_CryptStream{
public function stream_close() {
$this->flush();
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);
}

View File

@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @return bool
*/
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'];
}
@ -68,14 +68,14 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (!is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($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) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
$cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data=OC_Crypt::blockDecrypt($data,'',$cached['size']);
}
return $data;
@ -113,7 +113,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postStat($path,$data) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
$cached=\OC\Files\Filesystem::getFileInfo($path,'');
$data['size']=$cached['size'];
}
return $data;
@ -121,7 +121,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postFileSize($path,$size) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
$cached=\OC\Files\Filesystem::getFileInfo($path,'');
return $cached['size'];
}else{
return $size;

View File

@ -10,6 +10,7 @@ if (version_compare($installedVersion, '0.3', '<')) {
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
while ($row = $result->fetchRow()) {
$meta = \OC\Files\Filesystem::getId($path, '');
$itemSource = OC_FileCache::getId($row['source'], '');
if ($itemSource != -1) {
$file = OC_FileCache::get($row['source'], '');
@ -70,4 +71,4 @@ if (version_compare($installedVersion, '0.3.3', '<')) {
foreach ($users as $user) {
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;
if (is_null($info)) {
$info = OC_Files::getFileInfo($path);
$info = \OC\Files\Filesystem::getFileInfo($path);
}
if (!$info) {
@ -117,7 +117,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public function getChildren() {
$folder_content = OC_Files::getDirectoryContent($this->path);
$folder_content = \OC\Files\Filesystem::getDirectoryContent($this->path);
$paths = array();
foreach($folder_content as $info) {
$paths[] = $this->path.'/'.$info['name'];
@ -178,7 +178,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* @return array
*/
public function getQuotaInfo() {
$rootInfo=OC_FileCache_Cached::get('');
$rootInfo=\OC\Files\Filesystem::getFileInfo('');
return array(
$rootInfo['size'],
\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() {
if (!isset($this->fileinfo_cache)) {
if ($fileinfo_cache = \OC\Files\Filesystem::get($this->path)) {
if ($fileinfo_cache = \OC\Files\Filesystem::getFileInfo($this->path)) {
} else {
$fileinfo_cache = \OC\Files\Filesystem::stat($this->path);
}

View File

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

View File

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

View File

@ -627,6 +627,19 @@ class Filesystem {
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
*

View File

@ -451,7 +451,6 @@ class View {
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
// OC_FileCache_Update::update($path2, $this->fakeRoot);
Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot);
}
return $result;

View File

@ -590,8 +590,8 @@ class OC_OCS {
// calculate the disc space
$user_dir = '/'.$user.'/files';
\OC\Files\Filesystem::init($user_dir);
$rootInfo=OC_FileCache::get('');
$sharedInfo=OC_FileCache::get('/Shared');
$rootInfo=\OC\Files\Filesystem::getFileInfo('');
$sharedInfo=\OC\Files\Filesystem::getFileInfo('/Shared');
$used=$rootInfo['size']-$sharedInfo['size'];
$free=\OC\Files\Filesystem::free_space();
$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 ($itemType == 'folder') {
$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++) {
$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
array_push($files, $children);
} else {
@ -768,9 +768,10 @@ class Share {
if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
$childItem['file_source'] = $child['source'];
} 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 ($childItem[$column] == $item) {
@ -881,7 +882,8 @@ class Share {
if ($itemType == 'file' || $itemType == 'folder') {
$fileSource = $itemSource;
} else {
$fileSource = \OC_FileCache::getId($filePath);
$meta = \OC\Files\Filesystem::getFileInfo($filePath);
$fileSource = $meta['fileid'];
}
if ($fileSource == -1) {
$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 ($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;
}
} else if ($item['item_source'] == $itemSource) {

View File

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

View File

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