Commit 617dc0e4 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge branch 'master' into moviepreviewfallback

Conflicts:
	lib/private/preview/movies.php
parents 99ee95d4 ecc7b01c
......@@ -10,7 +10,7 @@ OCP\JSON::checkLoggedIn();
// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
header("HTTP/1.0 404 Not Found");
exit();
......
......@@ -36,6 +36,7 @@ OCP\Util::addscript('files', 'filelist');
OCP\App::setActiveNavigationEntry('files_index');
// Load the files
$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
// Redirect if directory does not exist
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
header('Location: ' . OCP\Util::getScriptName() . '');
......@@ -128,7 +129,7 @@ if ($needUpgrade) {
$tmpl = new OCP\Template('files', 'index', 'user');
$tmpl->assign('fileList', $list->fetchPage());
$tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
$tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($dir));
$tmpl->assign('dir', $dir);
$tmpl->assign('isCreatable', $isCreatable);
$tmpl->assign('permissions', $permissions);
$tmpl->assign('files', $files);
......
......@@ -303,16 +303,15 @@ $(document).ready(function() {
OC.Upload.log('fail', e, data);
if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) {
if (data.textStatus === 'abort') {
$('#notification').text(t('files', 'Upload cancelled.'));
OC.Notification.show(t('files', 'Upload cancelled.'));
} else {
// HTTP connection problem
$('#notification').text(data.errorThrown);
OC.Notification.show(data.errorThrown);
}
$('#notification').fadeIn();
//hide notification after 5 sec
//hide notification after 10 sec
setTimeout(function() {
$('#notification').fadeOut();
}, 5000);
OC.Notification.hide();
}, 10000);
}
OC.Upload.deleteUpload(data);
},
......
......@@ -170,6 +170,12 @@ var FileList={
return;
}
FileList.setCurrentDir(targetDir, changeUrl);
$('#fileList').trigger(
jQuery.Event('changeDirectory', {
dir: targetDir,
previousDir: currentDir
}
));
FileList.reload();
},
linkTo: function(dir) {
......@@ -654,19 +660,19 @@ var FileList={
$('.summary .filesize').html(humanFileSize(fileSummary.totalSize));
// Show only what's necessary (may be hidden)
if ($dirInfo.html().charAt(0) === "0") {
if (fileSummary.totalDirs === 0) {
$dirInfo.hide();
$connector.hide();
} else {
$dirInfo.show();
}
if ($fileInfo.html().charAt(0) === "0") {
if (fileSummary.totalFiles === 0) {
$fileInfo.hide();
$connector.hide();
} else {
$fileInfo.show();
}
if ($dirInfo.html().charAt(0) !== "0" && $fileInfo.html().charAt(0) !== "0") {
if (fileSummary.totalDirs > 0 && fileSummary.totalFiles > 0) {
$connector.show();
}
}
......
......@@ -636,7 +636,7 @@ function procesSelection() {
if (selectedFiles.length>0) {
selection += n('files', '%n file', '%n files', selectedFiles.length);
}
$('#headerName>span.name').text(selection);
$('#headerName span.name').text(selection);
$('#modified').text('');
$('table').addClass('multiselect');
}
......
......@@ -60,6 +60,7 @@ $TRANSLATIONS = array(
"Name" => "Nome",
"Size" => "Tamanho",
"Modified" => "Modificado",
"Invalid folder name. Usage of 'Shared' is reserved." => "Nome da pasta inválido. Uso de 'Shared' é reservado.",
"%s could not be renamed" => "%s não pode ser renomeado",
"Upload" => "Upload",
"File handling" => "Tratamento de Arquivo",
......
......@@ -8,6 +8,7 @@ $TRANSLATIONS = array(
"_Uploading %n file_::_Uploading %n files_" => array("","",""),
"Error" => "Ошибка",
"Upload" => "Загрузка",
"Save" => "Сохранить",
"Cancel upload" => "Отмена загрузки",
"Download" => "Загрузка"
);
......
<?php
$TRANSLATIONS = array(
"_%n folder_::_%n folders_" => array(""),
"_%n file_::_%n files_" => array(""),
"_Uploading %n file_::_Uploading %n files_" => array("")
);
$PLURAL_FORMS = "nplurals=1; plural=0;";
......@@ -9,6 +9,7 @@ $TRANSLATIONS = array(
"Private key password successfully updated." => "Senha de chave privada atualizada com sucesso.",
"Could not update the private key password. Maybe the old password was not correct." => "Não foi possível atualizar a senha de chave privada. Talvez a senha antiga esteja incorreta.",
"Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app." => "Aplicativo de criptografia não foi inicializado! Talvez o aplicativo de criptografia tenha sido reativado durante essa sessão. Por favor, tente fazer logoff e login novamente para inicializar o aplicativo de criptografia.",
"Your private key is not valid! Likely your password was changed outside of %s (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files." => "Sua chave privada não é válida! Provavelmente sua senha foi alterada fora de %s (por exemplo, seu diretório corporativo). Você pode atualizar sua senha de chave privada em suas configurações pessoais para recuperar o acesso a seus arquivos criptografados.",
"Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you." => "Este arquivo não pode ser decriptado, provavelmente este é um arquivo compartilhado. Poe favoe peça ao dono do arquivo para compartilha-lo com você.",
"Unknown error please check your system settings or contact your administrator" => "Erro desconhecido, por favor verifique suas configurações ou faça contato com o administrador",
"Missing requirements." => "Requisitos não encontrados.",
......
......@@ -157,6 +157,49 @@ class Helper {
return $return;
}
/**
* @brief Check if a path is a .part file
* @param string $path Path that may identify a .part file
* @return bool
*/
public static function isPartialFilePath($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ( $extension === 'part' || $extension === 'etmp') {
return true;
} else {
return false;
}
}
/**
* @brief Remove .path extension from a file path
* @param string $path Path that may identify a .part file
* @return string File path without .part extension
* @note this is needed for reusing keys
*/
public static function stripPartialFileExtension($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ( $extension === 'part' || $extension === 'etmp') {
$newLength = strlen($path) - 5; // 5 = strlen(".part") = strlen(".etmp")
$fPath = substr($path, 0, $newLength);
// if path also contains a transaction id, we remove it too
$extension = pathinfo($fPath, PATHINFO_EXTENSION);
if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId")
$newLength = strlen($fPath) - strlen($extension) -1;
$fPath = substr($fPath, 0, $newLength);
}
return $fPath;
} else {
return $path;
}
}
/**
* @brief disable recovery
......
......@@ -152,10 +152,10 @@ class Keymanager {
}
// try reusing key file if part file
if (self::isPartialFilePath($targetPath)) {
if (Helper::isPartialFilePath($targetPath)) {
$result = $view->file_put_contents(
$basePath . '/' . self::fixPartialFilePath($targetPath) . '.key', $catfile);
$basePath . '/' . Helper::stripPartialFileExtension($targetPath) . '.key', $catfile);
} else {
......@@ -169,48 +169,6 @@ class Keymanager {
}
/**
* @brief Remove .path extension from a file path
* @param string $path Path that may identify a .part file
* @return string File path without .part extension
* @note this is needed for reusing keys
*/
public static function fixPartialFilePath($path) {
if (preg_match('/\.part$/', $path) || preg_match('/\.etmp$/', $path)) {
$newLength = strlen($path) - 5;
$fPath = substr($path, 0, $newLength);
return $fPath;
} else {
return $path;
}
}
/**
* @brief Check if a path is a .part file
* @param string $path Path that may identify a .part file
* @return bool
*/
public static function isPartialFilePath($path) {
if (preg_match('/\.part$/', $path) || preg_match('/\.etmp$/', $path)) {
return true;
} else {
return false;
}
}
/**
* @brief retrieve keyfile for an encrypted file
* @param \OC_FilesystemView $view
......@@ -226,7 +184,7 @@ class Keymanager {
$util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath);
$filename = self::fixPartialFilePath($filename);
$filename = Helper::stripPartialFileExtension($filename);
$filePath_f = ltrim($filename, '/');
// in case of system wide mount points the keys are stored directly in the data directory
......@@ -385,8 +343,8 @@ class Keymanager {
foreach ($shareKeys as $userId => $shareKey) {
// try reusing key file if part file
if (self::isPartialFilePath($shareKeyPath)) {
$writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
if (Helper::isPartialFilePath($shareKeyPath)) {
$writePath = $basePath . '/' . Helper::stripPartialFileExtension($shareKeyPath) . '.' . $userId . '.shareKey';
} else {
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
}
......@@ -422,7 +380,7 @@ class Keymanager {
$util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath);
$filename = self::fixPartialFilePath($filename);
$filename = Helper::stripPartialFileExtension($filename);
// in case of system wide mount points the keys are stored directly in the data directory
if ($util->isSystemWideMountPoint($filename)) {
$shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey';
......
......@@ -342,7 +342,7 @@ class Proxy extends \OC_FileProxy {
$fileInfo = false;
// get file info from database/cache if not .part file
if (!Keymanager::isPartialFilePath($path)) {
if (!Helper::isPartialFilePath($path)) {
$fileInfo = $view->getFileInfo($path);
}
......@@ -353,7 +353,7 @@ class Proxy extends \OC_FileProxy {
$fixSize = $util->getFileSize($path);
$fileInfo['unencrypted_size'] = $fixSize;
// put file info if not .part file
if (!Keymanager::isPartialFilePath($relativePath)) {
if (!Helper::isPartialFilePath($relativePath)) {
$view->putFileInfo($path, $fileInfo);
}
}
......@@ -372,7 +372,7 @@ class Proxy extends \OC_FileProxy {
$fileInfo['unencrypted_size'] = $size;
// put file info if not .part file
if (!Keymanager::isPartialFilePath($relativePath)) {
if (!Helper::isPartialFilePath($relativePath)) {
$view->putFileInfo($path, $fileInfo);
}
}
......
......@@ -1145,10 +1145,7 @@ class Util {
// Make sure that a share key is generated for the owner too
list($owner, $ownerPath) = $this->getUidAndFilename($filePath);
$pathinfo = pathinfo($ownerPath);
if(array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') {
$ownerPath = $pathinfo['dirname'] . '/' . $pathinfo['filename'];
}
$ownerPath = \OCA\Encryption\Helper::stripPartialFileExtension($ownerPath);
$userIds = array();
if ($sharingEnabled) {
......
<?php
/**
* Copyright (c) 2013 Bjoern Schiessle <schiessle@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
require_once __DIR__ . '/../lib/helper.php';
use OCA\Encryption;
/**
* Class Test_Encryption_Helper
*/
class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
/**
* @medium
*/
function testStripPartialFileExtension() {
$partFilename = 'testfile.txt.part';
$filename = 'testfile.txt';
$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
}
/**
* @medium
*/
function testStripPartialFileExtensionWithTransferIdPath() {
$partFilename = 'testfile.txt.ocTransferId643653835.part';
$filename = 'testfile.txt';
$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
}
}
\ No newline at end of file
......@@ -188,23 +188,6 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('key', $sslInfoPrivate);
}
/**
* @medium
*/
function testFixPartialFilePath() {
$partFilename = 'testfile.txt.part';
$filename = 'testfile.txt';
$this->assertTrue(Encryption\Keymanager::isPartialFilePath($partFilename));
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($partFilename));
$this->assertFalse(Encryption\Keymanager::isPartialFilePath($filename));
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($filename));
}
/**
* @medium
*/
......
......@@ -18,3 +18,7 @@ tr:hover>td.remove>img { visibility:visible; cursor:pointer; }
#addMountPoint>td { border:none; }
#addMountPoint>td.applicable { visibility:hidden; }
#selectBackend { margin-left:-10px; }
#externalStorage label > input[type="checkbox"] {
margin-right: 3px;
}
......@@ -34,16 +34,16 @@ class Shared extends \OC\Files\Storage\Common {
$this->sharedFolder = $arguments['sharedFolder'];
}
public function getId(){
public function getId() {
return 'shared::' . $this->sharedFolder;
}
/**
* @brief Get the source file path, permissions, and owner for a shared file
* @param string Shared target file path
* @return Returns array with the keys path, permissions, and owner or false if not found
*/
private function getFile($target) {
* @brief Get the source file path, permissions, and owner for a shared file
* @param string Shared target file path
* @return Returns array with the keys path, permissions, and owner or false if not found
*/
public function getFile($target) {
if (!isset($this->files[$target])) {
// Check for partial files
if (pathinfo($target, PATHINFO_EXTENSION) === 'part') {
......@@ -62,18 +62,18 @@ class Shared extends \OC\Files\Storage\Common {
}
/**
* @brief Get the source file path for a shared file
* @param string Shared target file path
* @return string source file path or false if not found
*/
private function getSourcePath($target) {
* @brief Get the source file path for a shared file
* @param string Shared target file path
* @return string source file path or false if not found
*/
public function getSourcePath($target) {
$source = $this->getFile($target);
if ($source) {
if (!isset($source['fullPath'])) {
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
if (is_array($mount)) {
$this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint().$source['path'];
$this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint() . $source['path'];
} else {
$this->files[$target]['fullPath'] = false;
}
......@@ -84,10 +84,10 @@ class Shared extends \OC\Files\Storage\Common {
}
/**
* @brief Get the permissions granted for a shared file
* @param string Shared target file path
* @return int CRUDS permissions granted or false if not found
*/
* @brief Get the permissions granted for a shared file
* @param string Shared target file path
* @return int CRUDS permissions granted or false if not found
*/
public function getPermissions($target) {
$source = $this->getFile($target);
if ($source) {
......@@ -222,7 +222,7 @@ class Shared extends \OC\Files\Storage\Common {
if ($path == '' || $path == '/') {
$mtime = 0;
$dh = $this->opendir($path);
if(is_resource($dh)) {
if (is_resource($dh)) {
while (($filename = readdir($dh)) !== false) {
$tempmtime = $this->filemtime($filename);
if ($tempmtime > $mtime) {
......@@ -244,7 +244,7 @@ class Shared extends \OC\Files\Storage\Common {
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
'target' => $this->sharedFolder.$path,
'target' => $this->sharedFolder . $path,
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
......@@ -257,13 +257,14 @@ class Shared extends \OC\Files\Storage\Common {
if ($source = $this->getSourcePath($path)) {
// Check if permission is granted
if (($this->file_exists($path) && !$this->isUpdatable($path))
|| ($this->is_dir($path) && !$this->isCreatable($path))) {
|| ($this->is_dir($path) && !$this->isCreatable($path))
) {
return false;
}
$info = array(
'target' => $this->sharedFolder.$path,
'source' => $source,
);
'target' => $this->sharedFolder . $path,
'source' => $source,
);
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
$result = $storage->file_put_contents($internalPath, $data);
......@@ -304,31 +305,16 @@ class Shared extends \OC\Files\Storage\Common {
$pos1 = strpos($path1, '/', 1);
$pos2 = strpos($path2, '/', 1);
if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) {
$newSource = $this->getSourcePath(dirname($path2)).'/'.basename($path2);
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
return $storage->rename($oldInternalPath, $newInternalPath);
}
} else {
// Move the file if DELETE and CREATE permissions are granted
if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
// Get the root shared folder
$folder1 = substr($path1, 0, $pos1);
$folder2 = substr($path2, 0, $pos2);
// Copy and unlink the file if it exists in a different shared folder
if ($folder1 != $folder2) {
if ($this->copy($path1, $path2)) {
return $this->unlink($path1);
}
} else {
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
return $storage->rename($oldInternalPath, $newInternalPath);
}
}
$newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2);
// Within the same folder, we only need UPDATE permissions
if (dirname($path1) == dirname($path2) and $this->isUpdatable($path1)) {
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
return $storage->rename($oldInternalPath, $newInternalPath);
// otherwise DELETE and CREATE permissions required
} elseif ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
$rootView = new \OC\Files\View('');
return $rootView->rename($oldSource, $newSource);
}
}
}
......@@ -338,10 +324,10 @@ class Shared extends \OC\Files\Storage\Common {
public function copy($path1, $path2) {
// Copy the file if CREATE permission is granted
if ($this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
list ($count, $result) = \OC_Helper::streamCopy($source, $target);
return $result;
$oldSource = $this->getSourcePath($path1);
$newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2);
$rootView = new \OC\Files\View('');
return $rootView->copy($oldSource, $newSource);
}
return false;
}
......@@ -363,16 +349,16 @@ class Shared extends \OC\Files\Storage\Common {
case 'xb':
case 'a':
case 'ab':
$exists = $this->file_exists($path);
if ($exists && !$this->isUpdatable($path)) {
return false;
}
if (!$exists && !$this->isCreatable(dirname($path))) {
return false;
}
$exists = $this->file_exists($path);
if ($exists && !$this->isUpdatable($path)) {
return false;
}
if (!$exists && !$this->isCreatable(dirname($path))) {
return false;
}
}
$info = array(
'target' => $this->sharedFolder.$path,
'target' => $this->sharedFolder . $path,
'source' => $source,
'mode' => $mode,
);
......@@ -412,6 +398,7 @@ class Shared extends \OC\Files\Storage\Common {
}
return false;
}
public function touch($path, $mtime = null) {
if ($source = $this->getSourcePath($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
......@@ -422,11 +409,12 @@ class Shared extends \OC\Files\Storage\Common {
public static function setup($options) {
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
|| \OCP\Share::getItemsSharedWith('file')) {
|| \OCP\Share::getItemsSharedWith('file')
) {