diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/l10n/et_EE.js | 1 | ||||
-rw-r--r-- | lib/l10n/et_EE.json | 1 | ||||
-rw-r--r-- | lib/private/appframework/http/request.php | 2 | ||||
-rw-r--r-- | lib/private/files/cache/scanner.php | 4 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 26 | ||||
-rw-r--r-- | lib/private/files/utils/scanner.php | 7 | ||||
-rw-r--r-- | lib/private/helper.php | 4 | ||||
-rw-r--r-- | lib/private/l10n.php | 26 | ||||
-rw-r--r-- | lib/private/preview.php | 43 | ||||
-rw-r--r-- | lib/private/preview/image.php | 6 | ||||
-rw-r--r-- | lib/private/preview/txt.php | 2 | ||||
-rw-r--r-- | lib/private/repair.php | 2 | ||||
-rw-r--r-- | lib/repair/repairinvalidshares.php | 79 |
13 files changed, 163 insertions, 40 deletions
diff --git a/lib/l10n/et_EE.js b/lib/l10n/et_EE.js index c821776dfe9..378693d4538 100644 --- a/lib/l10n/et_EE.js +++ b/lib/l10n/et_EE.js @@ -14,6 +14,7 @@ OC.L10N.register( "The library %s is not available." : "Teek %s pole saadaval.", "Following platforms are supported: %s" : "Toetatud on järgnevad platformid: %s", "ownCloud %s or higher is required." : "ownCloud %s või uuem on nõutav.", + "ownCloud %s or lower is required." : "ownCloud %s või vanem on nõutav.", "Help" : "Abiinfo", "Personal" : "Isiklik", "Users" : "Kasutajad", diff --git a/lib/l10n/et_EE.json b/lib/l10n/et_EE.json index 9ab7cd7e2ac..e5bfae2a91d 100644 --- a/lib/l10n/et_EE.json +++ b/lib/l10n/et_EE.json @@ -12,6 +12,7 @@ "The library %s is not available." : "Teek %s pole saadaval.", "Following platforms are supported: %s" : "Toetatud on järgnevad platformid: %s", "ownCloud %s or higher is required." : "ownCloud %s või uuem on nõutav.", + "ownCloud %s or lower is required." : "ownCloud %s või vanem on nõutav.", "Help" : "Abiinfo", "Personal" : "Isiklik", "Users" : "Kasutajad", diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php index b430673f9a9..af6015b0eef 100644 --- a/lib/private/appframework/http/request.php +++ b/lib/private/appframework/http/request.php @@ -603,7 +603,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { if (strpos($pathInfo, $name) === 0) { $pathInfo = substr($pathInfo, strlen($name)); } - if($pathInfo === '/'){ + if($pathInfo === false || $pathInfo === '/'){ return ''; } else { return $pathInfo; diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index fb60ee5aa53..bfdab16b645 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -186,9 +186,9 @@ class Scanner extends BasicEmitter { } if (!empty($newData)) { $data['fileid'] = $this->addToCache($file, $newData, $fileId); - $this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId)); - \OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId)); } + $this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId)); + \OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId)); } else { $this->removeFromCache($file); } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 805a2bc1ad0..c80e935b982 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -232,7 +232,11 @@ class Encryption extends Wrapper { $result = $this->storage->rename($path1, $path2); - if ($result && $this->encryptionManager->isEnabled()) { + if ($result && + // versions always use the keys from the original file, so we can skip + // this step for versions + $this->isVersion($path2) === false && + $this->encryptionManager->isEnabled()) { $source = $this->getFullPath($path1); if (!$this->util->isExcluded($source)) { $target = $this->getFullPath($path2); @@ -449,7 +453,7 @@ class Encryption extends Wrapper { public function copyFromStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { // TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed: - // - call $this->storage->moveFromStorage() instead of $this->copyBetweenStorage + // - call $this->storage->copyFromStorage() instead of $this->copyBetweenStorage // - copy the file cache update from $this->copyBetweenStorage to this method // - copy the copyKeys() call from $this->copyBetweenStorage to this method // - remove $this->copyBetweenStorage @@ -469,6 +473,13 @@ class Encryption extends Wrapper { */ private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) { + // for versions we have nothing to do, because versions should always use the + // key from the original file. Just create a 1:1 copy and done + if ($this->isVersion($targetInternalPath) || + $this->isVersion($sourceInternalPath)) { + return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } + // first copy the keys that we reuse the existing file key on the target location // and don't create a new one which would break versions for example. $mount = $this->mountManager->findByStorageId($sourceStorage->getId()); @@ -741,4 +752,15 @@ class Encryption extends Wrapper { return false; } + /** + * check if path points to a files version + * + * @param $path + * @return bool + */ + protected function isVersion($path) { + $normalized = Filesystem::normalizePath($path); + return substr($normalized, 0, strlen('/files_versions/')) === '/files_versions/'; + } + } diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index c70f4beb31d..558a1fba028 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -99,7 +99,12 @@ class Scanner extends PublicEmitter { $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); }); - + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); + }); + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); + }); // propagate etag and mtimes when files are changed or removed $propagator = $this->propagator; $propagatorListener = function ($path) use ($mount, $propagator) { diff --git a/lib/private/helper.php b/lib/private/helper.php index f2f72fddcfb..ba1240a5218 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -193,11 +193,11 @@ class OC_Helper { * Returns the path to the preview of the file. */ public static function previewIcon($path) { - return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => $path )); + return self::linkToRoute( 'core_ajax_preview', array('x' => 32, 'y' => 32, 'file' => $path )); } public static function publicPreviewIcon( $path, $token ) { - return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => $path, 't' => $token)); + return self::linkToRoute( 'core_ajax_public_preview', array('x' => 32, 'y' => 32, 'file' => $path, 't' => $token)); } /** diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 168011cfcec..89ce2bc8d72 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -102,16 +102,11 @@ class OC_L10N implements \OCP\IL10N { } /** - * @param $app * @return string */ - public static function setLanguageFromRequest($app = null) { + public static function setLanguageFromRequest() { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - if (is_array($app)) { - $available = $app; - } else { - $available = self::findAvailableLanguages($app); - } + $available = self::findAvailableLanguages(); // E.g. make sure that 'de' is before 'de_DE'. sort($available); @@ -122,17 +117,13 @@ class OC_L10N implements \OCP\IL10N { $preferred_language = str_replace('-', '_', $preferred_language); foreach ($available as $available_language) { if ($preferred_language === strtolower($available_language)) { - if (!is_array($app)) { - self::$language = $available_language; - } + self::$language = $available_language; return $available_language; } } foreach ($available as $available_language) { if (substr($preferred_language, 0, 2) === $available_language) { - if (!is_array($app)) { - self::$language = $available_language; - } + self::$language = $available_language; return $available_language; } } @@ -469,7 +460,7 @@ class OC_L10N implements \OCP\IL10N { return $default_language; } - $lang = self::setLanguageFromRequest($app); + $lang = self::setLanguageFromRequest(); if($userId && !$config->getUserValue($userId, 'core', 'lang')) { $config->setUserValue($userId, 'core', 'lang', $lang); } @@ -503,8 +494,9 @@ class OC_L10N implements \OCP\IL10N { * @return array an array of available languages */ public static function findAvailableLanguages($app=null) { - if(!empty(self::$availableLanguages)) { - return self::$availableLanguages; + // also works with null as key + if(isset(self::$availableLanguages[$app]) && !empty(self::$availableLanguages[$app])) { + return self::$availableLanguages[$app]; } $available=array('en');//english is always available $dir = self::findI18nDir($app); @@ -518,7 +510,7 @@ class OC_L10N implements \OCP\IL10N { } } - self::$availableLanguages = $available; + self::$availableLanguages[$app] = $available; return $available; } diff --git a/lib/private/preview.php b/lib/private/preview.php index de964b72df2..b2accdfd00f 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -252,12 +252,13 @@ class Preview { * Sets the path of the file you want a preview of * * @param string $file + * @param \OCP\Files\FileInfo|null $info * * @return \OC\Preview */ - public function setFile($file) { + public function setFile($file, $info = null) { $this->file = $file; - $this->info = null; + $this->info = $info; if ($file !== '') { $this->getFileInfo(); @@ -374,7 +375,7 @@ class Preview { return false; } - if (!$this->fileView->file_exists($file)) { + if (!$this->getFileInfo() instanceof FileInfo) { \OCP\Util::writeLog('core', 'File:"' . $file . '" not found', \OCP\Util::DEBUG); return false; @@ -478,7 +479,7 @@ class Preview { $preview = $this->buildCachePath($fileId, $previewWidth, $previewHeight); // This checks if we have a preview of those exact dimensions in the cache - if ($this->userView->file_exists($preview)) { + if ($this->thumbnailSizeExists($allThumbnails, basename($preview))) { return $preview; } @@ -524,6 +525,24 @@ class Preview { } /** + * Check if a specific thumbnail size is cached + * + * @param FileInfo[] $allThumbnails the list of all our cached thumbnails + * @param string $name + * @return bool + */ + private function thumbnailSizeExists(array $allThumbnails, $name) { + + foreach ($allThumbnails as $thumbnail) { + if ($name === $thumbnail->getName()) { + return true; + } + } + + return false; + } + + /** * Determines the size of the preview we should be looking for in the cache * * @return int[] @@ -837,6 +856,11 @@ class Preview { $askedWidth = $this->getMaxX(); $askedHeight = $this->getMaxY(); + if ($this->mode === self::MODE_COVER) { + list($askedWidth, $askedHeight) = + $this->applyCover($askedWidth, $askedHeight, $previewWidth, $previewHeight); + } + /** * Phase 1: If required, adjust boundaries to keep aspect ratio */ @@ -845,20 +869,12 @@ class Preview { $this->applyAspectRatio($askedWidth, $askedHeight, $previewWidth, $previewHeight); } - if ($this->mode === self::MODE_COVER) { - list($scaleWidth, $scaleHeight) = - $this->applyCover($askedWidth, $askedHeight, $previewWidth, $previewHeight); - } else { - $scaleWidth = $askedWidth; - $scaleHeight = $askedHeight; - } - /** * Phase 2: Resizes preview to try and match requirements. * Takes the scaling ratio into consideration */ list($newPreviewWidth, $newPreviewHeight) = $this->scale( - $image, $scaleWidth, $scaleHeight, $previewWidth, $previewHeight + $image, $askedWidth, $askedHeight, $previewWidth, $previewHeight ); // The preview has been resized and should now have the asked dimensions @@ -890,6 +906,7 @@ class Preview { return; } + // The preview is smaller, but we can't touch it $this->storePreview($fileId, $newPreviewWidth, $newPreviewHeight); } diff --git a/lib/private/preview/image.php b/lib/private/preview/image.php index f9c27e690f6..fd90b15eb0c 100644 --- a/lib/private/preview/image.php +++ b/lib/private/preview/image.php @@ -46,12 +46,16 @@ abstract class Image extends Provider { $image = new \OC_Image(); - if ($fileInfo['encrypted'] === true) { + $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal(); + if ($useTempFile) { $fileName = $fileview->toTmpFile($path); } else { $fileName = $fileview->getLocalFile($path); } $image->loadFromFile($fileName); + if ($useTempFile) { + unlink($fileName); + } $image->fixOrientation(); if ($image->valid()) { $image->scaleDownToFit($maxX, $maxY); diff --git a/lib/private/preview/txt.php b/lib/private/preview/txt.php index 0bba570a8c9..2fdc86d9546 100644 --- a/lib/private/preview/txt.php +++ b/lib/private/preview/txt.php @@ -53,7 +53,7 @@ class TXT extends Provider { $lines = preg_split("/\r\n|\n|\r/", $content); - $fontSize = ($maxX) ? (int) ((5 / 36) * $maxX) : 5; //5px + $fontSize = ($maxX) ? (int) ((5 / 32) * $maxX) : 5; //5px $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); diff --git a/lib/private/repair.php b/lib/private/repair.php index 3639440a518..20219e313fd 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -44,6 +44,7 @@ use OC\Repair\RepairLegacyStorages; use OC\Repair\RepairMimeTypes; use OC\Repair\SearchLuceneTables; use OC\Repair\UpdateOutdatedOcsIds; +use OC\Repair\RepairInvalidShares; class Repair extends BasicEmitter { /** @@ -113,6 +114,7 @@ class Repair extends BasicEmitter { new DropOldJobs(\OC::$server->getJobList()), new RemoveGetETagEntries(\OC::$server->getDatabaseConnection()), new UpdateOutdatedOcsIds(\OC::$server->getConfig()), + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), ]; } diff --git a/lib/repair/repairinvalidshares.php b/lib/repair/repairinvalidshares.php new file mode 100644 index 00000000000..21b4d8013e7 --- /dev/null +++ b/lib/repair/repairinvalidshares.php @@ -0,0 +1,79 @@ +<?php +/** + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Repair; + +use OC\Hooks\BasicEmitter; + +/** + * Repairs shares with invalid data + */ +class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep { + + /** + * @var \OCP\IConfig + */ + protected $config; + + /** + * @var \OCP\IDBConnection + */ + protected $connection; + + /** + * @param \OCP\IConfig $config + * @param \OCP\IDBConnection $connection + */ + public function __construct($config, $connection) { + $this->connection = $connection; + $this->config = $config; + } + + public function getName() { + return 'Repair invalid shares'; + } + + /** + * Past bugs would make it possible to set an expiration date on user shares even + * though it is not supported. This functions removes the expiration date from such entries. + */ + private function removeExpirationDateFromNonLinkShares() { + $builder = $this->connection->getQueryBuilder(); + $builder + ->update('share') + ->set('expiration', 'null') + ->where($builder->expr()->isNotNull('expiration')) + ->andWhere($builder->expr()->neq('share_type', $builder->expr()->literal(\OC\Share\Constants::SHARE_TYPE_LINK))); + + $updatedEntries = $builder->execute(); + if ($updatedEntries > 0) { + $this->emit('\OC\Repair', 'info', array('Removed invalid expiration date from ' . $updatedEntries . ' shares')); + } + } + + public function run() { + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.7', '<')) { + // this situation was only possible before 8.2 + $this->removeExpirationDateFromNonLinkShares(); + } + } +} |