fix line endings

This commit is contained in:
Björn Schießle 2013-02-25 14:29:31 +01:00
parent 4c980a4851
commit e30b3f64e0

View file

@ -36,77 +36,77 @@ class Trashbin {
*/
public static function move2trash($file_path) {
$user = \OCP\User::getUser();
$view = new \OC\Files\View('/'. $user);
if (!$view->is_dir('files_trashbin')) {
$view->mkdir('files_trashbin');
$view = new \OC\Files\View('/'. $user);
if (!$view->is_dir('files_trashbin')) {
$view->mkdir('files_trashbin');
$view->mkdir("files_trashbin/files");
$view->mkdir("files_trashbin/versions");
$view->mkdir("files_trashbin/keyfiles");
}
$path_parts = pathinfo($file_path);
$deleted = $path_parts['basename'];
$location = $path_parts['dirname'];
$timestamp = time();
$mime = $view->getMimeType('files'.$file_path);
if ( $view->is_dir('files'.$file_path) ) {
$type = 'dir';
} else {
$type = 'file';
$view->mkdir("files_trashbin/keyfiles");
}
$path_parts = pathinfo($file_path);
$deleted = $path_parts['basename'];
$location = $path_parts['dirname'];
$timestamp = time();
$mime = $view->getMimeType('files'.$file_path);
if ( $view->is_dir('files'.$file_path) ) {
$type = 'dir';
} else {
$type = 'file';
}
$trashbinSize = self::getTrashbinSize($user);
$trashbinSize = self::getTrashbinSize($user);
if ( $trashbinSize === false || $trashbinSize < 0 ) {
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
}
$trashbinSize += self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view);
if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) {
if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) {
$query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)");
$result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user));
if ( !$result ) { // if file couldn't be added to the database than also don't store it in the trash bin.
$view->deleteAll('files_trashbin/files/'.$deleted.'.d'.$timestamp);
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
return;
}
}
// Take care of file versions
if ( \OCP\App::isEnabled('files_versions') ) {
// Take care of file versions
if ( \OCP\App::isEnabled('files_versions') ) {
if ( $view->is_dir('files_versions'.$file_path) ) {
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path));
$view->rename('files_versions'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp);
} else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path));
$view->rename('files_versions'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp);
} else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {
foreach ($versions as $v) {
$trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);
$view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
}
$trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);
$view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
}
}
}
// Take care of encryption keys
$keyfile = \OC_Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path);
$keyfile = \OC_Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path);
if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile.'.key') ) {
if ( $view->is_dir('files'.$file_path) ) {
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile));
$view->rename($keyfile, 'files_trashbin/keyfiles/'. $deleted.'.d'.$timestamp);
} else {
} else {
$trashbinSize += $view->filesize($keyfile.'.key');
$view->rename($keyfile.'.key', 'files_trashbin/keyfiles/'. $deleted.'.key.d'.$timestamp);
}
}
}
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR);
}
// get available disk space for user
$quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota'));
if ( $quota === null ) {
$quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));
}
if ( $quota === null ) {
// get available disk space for user
$quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota'));
if ( $quota === null ) {
$quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));
}
if ( $quota === null ) {
$quota = \OC\Files\Filesystem::free_space('/') / count(\OCP\User::getUsers());
}
@ -121,7 +121,7 @@ class Trashbin {
$trashbinSize -= self::expire($availableSpace);
self::setTrashbinSize($user, $trashbinSize);
self::setTrashbinSize($user, $trashbinSize);
}
@ -186,9 +186,9 @@ class Trashbin {
$versionedFile = $file;
}
if ( $result[0]['type'] === 'dir' ) {
$trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.'files_trashbin/versions/'. $file));
$view->rename(\OC_Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));
} else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {
$trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.'files_trashbin/versions/'. $file));
$view->rename(\OC_Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));
} else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {
foreach ($versions as $v) {
if ($timestamp ) {
$trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp);
@ -196,8 +196,8 @@ class Trashbin {
} else {
$trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v);
$view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
}
}
}
}
}
}
@ -210,15 +210,15 @@ class Trashbin {
}
if ($timestamp) {
$keyfile .= '.d'.$timestamp;
}
}
if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) {
if ( $result[0]['type'] === 'dir' ) {
if ( $result[0]['type'] === 'dir' ) {
$trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile));
$view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename);
} else {
$trashbinSize -= $view->filesize($keyfile);
$view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename.'.key');
}
}
}
if ( $timestamp ) {
@ -245,7 +245,7 @@ class Trashbin {
public static function delete($filename, $timestamp=null) {
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
$size = 0;
$size = 0;
$trashbinSize = self::getTrashbinSize($user);
if ( $trashbinSize === false || $trashbinSize < 0 ) {
@ -278,23 +278,23 @@ class Trashbin {
}
// Take care of encryption keys
$parts = pathinfo($file);
if ( $view->is_dir('/files_trashbin/files/'.$file) ) {
$keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename);
} else {
$keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key');
}
if ($timestamp) {
$keyfile .= '.d'.$timestamp;
}
if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) {
if ( $view->is_dir($keyfile) ) {
$size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile));
} else {
$size += $view->filesize($keyfile);
}
$view->unlink($keyfile);
}
$parts = pathinfo($file);
if ( $view->is_dir('/files_trashbin/files/'.$file) ) {
$keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename);
} else {
$keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key');
}
if ($timestamp) {
$keyfile .= '.d'.$timestamp;
}
if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) {
if ( $view->is_dir($keyfile) ) {
$size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile));
} else {
$size += $view->filesize($keyfile);
}
$view->unlink($keyfile);
}
if ($view->is_dir('/files_trashbin/files/'.$file)) {
$size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/files_trashbin/files/'.$file));
@ -304,7 +304,7 @@ class Trashbin {
$view->unlink('/files_trashbin/files/'.$file);
$trashbinSize -= $size;
self::setTrashbinSize($user, $trashbinSize);
return $size;
}
@ -477,35 +477,35 @@ class Trashbin {
return $size;
}
/**
* get current size of trash bin from a given user
*
* @param $user user who owns the trash bin
* @return mixed trash bin size or false if no trash bin size is stored
*/
private static function getTrashbinSize($user) {
$query = \OC_DB::prepare('SELECT size FROM *PREFIX*files_trashsize WHERE user=?');
$result = $query->execute(array($user))->fetchAll();
if ($result) {
return $result[0]['size'];
}
return false;
}
/**
* write to the database how much space is in use for the trash bin
*
* @param $user owner of the trash bin
* @param $size size of the trash bin
*/
private static function setTrashbinSize($user, $size) {
if ( self::getTrashbinSize($user) === false) {
$query = \OC_DB::prepare('INSERT INTO *PREFIX*files_trashsize (size, user) VALUES (?, ?)');
}else {
$query = \OC_DB::prepare('UPDATE *PREFIX*files_trashsize SET size=? WHERE user=?');
}
$query->execute(array($size, $user));
/**
* get current size of trash bin from a given user
*
* @param $user user who owns the trash bin
* @return mixed trash bin size or false if no trash bin size is stored
*/
private static function getTrashbinSize($user) {
$query = \OC_DB::prepare('SELECT size FROM *PREFIX*files_trashsize WHERE user=?');
$result = $query->execute(array($user))->fetchAll();
if ($result) {
return $result[0]['size'];
}
return false;
}
/**
* write to the database how much space is in use for the trash bin
*
* @param $user owner of the trash bin
* @param $size size of the trash bin
*/
private static function setTrashbinSize($user, $size) {
if ( self::getTrashbinSize($user) === false) {
$query = \OC_DB::prepare('INSERT INTO *PREFIX*files_trashsize (size, user) VALUES (?, ?)');
}else {
$query = \OC_DB::prepare('UPDATE *PREFIX*files_trashsize SET size=? WHERE user=?');
}
$query->execute(array($size, $user));
}
}