community/nextcloud: add upstream fix for project issue #6028

Remove chmod() from other places
This commit is contained in:
Leonardo Arena 2017-11-14 14:07:15 +00:00
parent cdb56c9dc7
commit 1f7e3605b0
6 changed files with 481 additions and 18 deletions

View File

@ -0,0 +1,34 @@
From b0d296639cfc5d0460987787cc9869c5e5473d85 Mon Sep 17 00:00:00 2001
From: Kyle Fazzari <kyrofa@ubuntu.com>
Date: Fri, 3 Nov 2017 23:03:34 -0700
Subject: [PATCH] CSSResourceLocator: account for symlinks in app path
Currently, if the app path includes a symlink, the calculated webDir
will be incorrect when generating CSS and URLs will be pointing to the
wrong place, breaking CSS.
Use realpath when retrieving app path, and these issues go away.
Fix #6028
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
---
lib/private/Template/CSSResourceLocator.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php
index 1028f31a5ea..bd5b9a34477 100644
--- a/lib/private/Template/CSSResourceLocator.php
+++ b/lib/private/Template/CSSResourceLocator.php
@@ -71,6 +71,11 @@ public function doFind($style) {
return;
}
+ // Account for the possibility of having symlinks in app path. Doing
+ // this here instead of above as an empty argument to realpath gets
+ // turned into cwd.
+ $app_path = realpath($app_path);
+
if(!$this->cacheAndAppendScssIfExist($app_path, $style.'.scss', $app)) {
$this->append($app_path, $style.'.css', $app_url);
}

View File

@ -0,0 +1,344 @@
From 06ba1a8a02f08e066ad97cdd192534c296f3a640 Mon Sep 17 00:00:00 2001
From: Kyle Fazzari <kyrofa@ubuntu.com>
Date: Tue, 7 Nov 2017 14:54:21 -0800
Subject: [PATCH] JSResourceLocator: account for symlinks in app path
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
---
lib/private/Template/JSResourceLocator.php | 11 +-
tests/lib/Template/CSSResourceLocatorTest.php | 148 ++++++++++++++++++++++++++
tests/lib/Template/JSResourceLocatorTest.php | 139 ++++++++++++++++++++++++
3 files changed, 295 insertions(+), 3 deletions(-)
create mode 100644 tests/lib/Template/CSSResourceLocatorTest.php
create mode 100644 tests/lib/Template/JSResourceLocatorTest.php
diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php
index 97a9eacedf5..228fa09e821 100644
--- a/lib/private/Template/JSResourceLocator.php
+++ b/lib/private/Template/JSResourceLocator.php
@@ -75,9 +75,14 @@ public function doFind($script) {
$app_path = \OC_App::getAppPath($app);
$app_url = \OC_App::getAppWebPath($app);
+ // Account for the possibility of having symlinks in app path. Doing
+ // this in a separate variable, because an empty argument to realpath
+ // gets turned into cwd, which makes it hard to see if app_path got set.
+ $real_app_path = realpath($app_path);
+
// missing translations files fill be ignored
if (strpos($script, 'l10n/') === 0) {
- $this->appendIfExist($app_path, $script . '.js', $app_url);
+ $this->appendIfExist($real_app_path, $script . '.js', $app_url);
return;
}
@@ -89,8 +94,8 @@ public function doFind($script) {
return;
}
- if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
- $this->append($app_path, $script . '.js', $app_url);
+ if (!$this->cacheAndAppendCombineJsonIfExist($real_app_path, $script.'.json', $app)) {
+ $this->append($real_app_path, $script . '.js', $app_url);
}
}
diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php
new file mode 100644
index 00000000000..bd13487282e
--- /dev/null
+++ b/tests/lib/Template/CSSResourceLocatorTest.php
@@ -0,0 +1,148 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Kyle Fazzari <kyrofa@ubuntu.com>
+ *
+ * @author Kyle Fazzari <kyrofa@ubuntu.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Template;
+
+use OC\Files\AppData\Factory;
+use OCP\ILogger;
+use OCP\IURLGenerator;
+use OCP\IConfig;
+use OCA\Theming\ThemingDefaults;
+use OCP\ICache;
+use OC\Template\SCSSCacher;
+use OC\Template\CSSResourceLocator;
+
+function rrmdir($directory) {
+ $files = array_diff(scandir($directory), array('.','..'));
+ foreach ($files as $file) {
+ if (is_dir($directory . '/' . $file)) {
+ rrmdir($directory . '/' . $file);
+ } else {
+ unlink($directory . '/' . $file);
+ }
+ }
+ return rmdir($directory);
+}
+
+function randomString() {
+ return sha1(uniqid(mt_rand(), true));
+}
+
+class CSSResourceLocatorTest extends \Test\TestCase {
+ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ protected $appData;
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
+ /** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
+ protected $themingDefaults;
+ /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
+ protected $depsCache;
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ protected $logger;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->logger = $this->createMock(ILogger::class);
+ $this->appData = $this->createMock(IAppData::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->depsCache = $this->createMock(ICache::class);
+ $this->themingDefaults = $this->createMock(ThemingDefaults::class);
+ }
+
+ private function cssResourceLocator() {
+ /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
+ $factory = $this->createMock(Factory::class);
+ $factory->method('get')->with('css')->willReturn($this->appData);
+ $scssCacher = new SCSSCacher(
+ $this->logger,
+ $factory,
+ $this->urlGenerator,
+ $this->config,
+ $this->themingDefaults,
+ \OC::$SERVERROOT,
+ $this->depsCache
+ );
+ return new CSSResourceLocator(
+ $this->logger,
+ 'theme',
+ array('core'=>'map'),
+ array('3rd'=>'party'),
+ $scssCacher
+ );
+ }
+
+ public function testConstructor() {
+ $locator = $this->cssResourceLocator();
+ $this->assertAttributeEquals('theme', 'theme', $locator);
+ $this->assertAttributeEquals('core', 'serverroot', $locator);
+ $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
+ $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
+ $this->assertAttributeEquals('map', 'webroot', $locator);
+ $this->assertAttributeEquals(array(), 'resources', $locator);
+ }
+
+ public function testFindWithAppPathSymlink() {
+ // First create new apps path, and a symlink to it
+ $apps_dirname = randomString();
+ $new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
+ $new_apps_path_symlink = $new_apps_path . '_link';
+ mkdir($new_apps_path);
+ symlink($apps_dirname, $new_apps_path_symlink);
+
+ // Create an app within that path
+ mkdir($new_apps_path . '/' . 'test-app');
+
+ // Use the symlink as the app path
+ \OC::$APPSROOTS[] = [
+ 'path' => $new_apps_path_symlink,
+ 'url' => '/apps-test',
+ 'writable' => false,
+ ];
+
+ $locator = $this->cssResourceLocator();
+ $locator->find(array('test-app/test-file'));
+
+ $resources = $locator->getResources();
+ $this->assertCount(1, $resources);
+ $resource = $resources[0];
+ $this->assertCount(3, $resource);
+ $root = $resource[0];
+ $webRoot = $resource[1];
+ $file = $resource[2];
+
+ $expectedRoot = $new_apps_path . '/test-app';
+ $expectedWebRoot = '/apps-test/test-app';
+ $expectedFile = 'test-file.css';
+
+ $this->assertEquals($expectedRoot, $root,
+ 'Ensure the app path symlink is resolved into the real path');
+ $this->assertEquals($expectedWebRoot, $webRoot);
+ $this->assertEquals($expectedFile, $file);
+
+ rrmdir($new_apps_path);
+ }
+}
diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php
new file mode 100644
index 00000000000..49f0fb67f48
--- /dev/null
+++ b/tests/lib/Template/JSResourceLocatorTest.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Kyle Fazzari <kyrofa@ubuntu.com>
+ *
+ * @author Kyle Fazzari <kyrofa@ubuntu.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Template;
+
+use OC\Template\JSCombiner;
+use OCP\Files\IAppData;
+use OCP\IURLGenerator;
+use OCP\ICache;
+use OC\SystemConfig;
+use OCP\ILogger;
+use OC\Template\JSResourceLocator;
+
+function rrmdir($directory) {
+ $files = array_diff(scandir($directory), array('.','..'));
+ foreach ($files as $file) {
+ if (is_dir($directory . '/' . $file)) {
+ rrmdir($directory . '/' . $file);
+ } else {
+ unlink($directory . '/' . $file);
+ }
+ }
+ return rmdir($directory);
+}
+
+function randomString() {
+ return sha1(uniqid(mt_rand(), true));
+}
+
+class JSResourceLocatorTest extends \Test\TestCase {
+ /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ protected $appData;
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
+ /** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
+ protected $depsCache;
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ protected $logger;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->appData = $this->createMock(IAppData::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->config = $this->createMock(SystemConfig::class);
+ $this->depsCache = $this->createMock(ICache::class);
+ $this->logger = $this->createMock(ILogger::class);
+ }
+
+ private function jsResourceLocator() {
+ $jsCombiner = new JSCombiner(
+ $this->appData,
+ $this->urlGenerator,
+ $this->depsCache,
+ $this->config,
+ $this->logger
+ );
+ return new JSResourceLocator(
+ $this->logger,
+ 'theme',
+ array('core'=>'map'),
+ array('3rd'=>'party'),
+ $jsCombiner
+ );
+ }
+
+ public function testConstructor() {
+ $locator = $this->jsResourceLocator();
+ $this->assertAttributeEquals('theme', 'theme', $locator);
+ $this->assertAttributeEquals('core', 'serverroot', $locator);
+ $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
+ $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
+ $this->assertAttributeEquals('map', 'webroot', $locator);
+ $this->assertAttributeEquals(array(), 'resources', $locator);
+ }
+
+ public function testFindWithAppPathSymlink() {
+ // First create new apps path, and a symlink to it
+ $apps_dirname = randomString();
+ $new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
+ $new_apps_path_symlink = $new_apps_path . '_link';
+ mkdir($new_apps_path);
+ symlink($apps_dirname, $new_apps_path_symlink);
+
+ // Create an app within that path
+ mkdir($new_apps_path . '/' . 'test-app');
+
+ // Use the symlink as the app path
+ \OC::$APPSROOTS[] = [
+ 'path' => $new_apps_path_symlink,
+ 'url' => '/apps-test',
+ 'writable' => false,
+ ];
+
+ $locator = $this->jsResourceLocator();
+ $locator->find(array('test-app/test-file'));
+
+ $resources = $locator->getResources();
+ $this->assertCount(1, $resources);
+ $resource = $resources[0];
+ $this->assertCount(3, $resource);
+ $root = $resource[0];
+ $webRoot = $resource[1];
+ $file = $resource[2];
+
+ $expectedRoot = $new_apps_path . '/test-app';
+ $expectedWebRoot = '/apps-test/test-app';
+ $expectedFile = 'test-file.js';
+
+ $this->assertEquals($expectedRoot, $root,
+ 'Ensure the app path symlink is resolved into the real path');
+ $this->assertEquals($expectedWebRoot, $webRoot);
+ $this->assertEquals($expectedFile, $file);
+
+ rrmdir($new_apps_path);
+ }
+}

View File

@ -0,0 +1,47 @@
From d2a2793073929194cdb2de31cfb331fc5e95346e Mon Sep 17 00:00:00 2001
From: Kyle Fazzari <kyrofa@ubuntu.com>
Date: Sun, 12 Nov 2017 08:08:38 -0800
Subject: [PATCH] JSResourceLocator: re-use $app_path
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
---
lib/private/Template/JSResourceLocator.php | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php
index 228fa09e821..93a737b66cc 100644
--- a/lib/private/Template/JSResourceLocator.php
+++ b/lib/private/Template/JSResourceLocator.php
@@ -75,14 +75,16 @@ public function doFind($script) {
$app_path = \OC_App::getAppPath($app);
$app_url = \OC_App::getAppWebPath($app);
- // Account for the possibility of having symlinks in app path. Doing
- // this in a separate variable, because an empty argument to realpath
- // gets turned into cwd, which makes it hard to see if app_path got set.
- $real_app_path = realpath($app_path);
+ if ($app_path !== false) {
+ // Account for the possibility of having symlinks in app path. Only
+ // do this if $app_path is set, because an empty argument to realpath
+ // gets turned into cwd.
+ $app_path = realpath($app_path);
+ }
// missing translations files fill be ignored
if (strpos($script, 'l10n/') === 0) {
- $this->appendIfExist($real_app_path, $script . '.js', $app_url);
+ $this->appendIfExist($app_path, $script . '.js', $app_url);
return;
}
@@ -94,8 +96,8 @@ public function doFind($script) {
return;
}
- if (!$this->cacheAndAppendCombineJsonIfExist($real_app_path, $script.'.json', $app)) {
- $this->append($real_app_path, $script . '.js', $app_url);
+ if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
+ $this->append($app_path, $script . '.js', $app_url);
}
}

View File

@ -2,7 +2,7 @@
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
pkgname=nextcloud
pkgver=12.0.3
pkgrel=0
pkgrel=1
pkgdesc="A safe home for all your data"
url="http://nextcloud.com"
arch="noarch"
@ -19,18 +19,22 @@ install="$pkgname.pre-install $pkgname.pre-upgrade $pkgname.post-upgrade"
subpackages="$pkgname-doc $pkgname-initscript $pkgname-mysql $pkgname-pgsql $pkgname-sqlite
$pkgname-default-apps:_default_apps"
source="https://download.nextcloud.com/server/releases/$pkgname-$pkgver.zip
nextcloud10-dont-chmod-config.patch
nextcloud10-dont-chmod.patch
dont-update-htaccess.patch
disable-integrity-check-as-default.patch
app-encryption-info-add-mcrypt.patch
iconv-ascii-translit-not-supported.patch
use-external-docs-if-local-not-avail.patch
nextcloud-1202-fix-6028.patch
0001-CSSResourceLocator-account-for-symlinks-in-app-path.patch
0002-JSResourceLocator-account-for-symlinks-in-app-path.patch
0003-JSResourceLocator-re-use-app_path.patch
$pkgname-config.php
$pkgname.logrotate
$pkgname.confd
$pkgname.cron
fpm-pool.conf"
fpm-pool.conf
"
options="!check"
pkgusers="nextcloud"
pkggroups="www-data"
@ -221,13 +225,15 @@ _package_app() {
}
sha512sums="f13f0810b1755abdcac8c72e69417baeebd759943afb6743530a136b440ac9bebded8dae282450056c0613f5982b15f41aefba3b766ebb5eaea3d3a0e82710cc nextcloud-12.0.3.zip
a12a73a38bc009d3307ce97bb32fc62ac93e125a77a3d36b31c9d2212953fa17bd5c31f819e0759a0645b1c285817b067143b0b9c3673ce4ab3043fae426a67c nextcloud10-dont-chmod-config.patch
9c20237c4952ff543171768160c17c3608cc43ad9592fecccaeb337787d566f039f27f30f118359dfff7db58cd12d811c05be15e5994efee57a9ed75787d71f5 nextcloud10-dont-chmod.patch
ec3921d4d463ed82be0be073af8064048a20f638424d1d39ab46db4252036e87ef2614570be91a5cef0c25c6bcaaf1a2725d2468bdb4a0fbee2b504a4dd0fbc8 dont-update-htaccess.patch
04783385ca35be9e8b895e91294b082cd2a1f50c4e17dc195901885ecd421db9a6fe45360d7eac623873ae4efad80b92f31ebde59f4ed76d832c8cac450dac85 disable-integrity-check-as-default.patch
8d3cb1436aa79f1ac0a7b4b3370fcfb5c50dbe811e631cabcb8170fb80da5967a88a15bc39cd04eaccffb3177bdf90fcba2a512e28e034e16d6bc9b445d2d137 app-encryption-info-add-mcrypt.patch
9bd1cdb73928d8e746286a8ededf79262835caee8fdb4a18e117535ed95784b5a0b04fad55c720084dd8ae1ed4fe123be55b41d3100c9bb0333af485084bc4b1 iconv-ascii-translit-not-supported.patch
478f5cd7c5d30380ea619d3e8ec623217a06a09b27534266f00297545c7d276b068c5d984673eebc5676e8bac7f45112549498944ce3fa678ac8a69541d7c430 use-external-docs-if-local-not-avail.patch
4c1de3c056473371a2288b9956ce1ecfe9eeb54e0561b7458c0cc38dbcf4ac2613dfe1fcea64715251b037a48eb1d7d29f32542fcea43c8ca1499db9b9f07cf3 nextcloud-1202-fix-6028.patch
391cc43f224239ab6113ab193ae6738eaf42dc0f4dfbfa1a401e833983b789c4eb552288dec82b8c9bbf0349596bbc8ff8481244b5aa171ed609a44393e33518 0001-CSSResourceLocator-account-for-symlinks-in-app-path.patch
004213fdc96a0d66364916475d7d5019ffce79aed941d79e9bd013a2d9aee7091ee04750fbd97919a6b03b14c3a898f46618cd612c0bcae386c5bc90a110b031 0002-JSResourceLocator-account-for-symlinks-in-app-path.patch
4e571b1a3fcfc8ad8b7bb87987b1d60fecb0603e23dccd3fbffc2e3e085bb2c726ca78b6c813ccb083760dccd8f8382e6dfe0ea3f1f46b6689e7c19c8754dde6 0003-JSResourceLocator-re-use-app_path.patch
89c941e2719629ee633421c4c75b55026c1a0a6b255e7f1f2c14612c10325045051b16dc5f17975af4a2a34ec187008de2eb15a53ac4cd06d26a5cbbd79fb73a nextcloud-config.php
f224d72799ee5819979089eb58978225454223bee597c938681a4f6279eb49297fe9250ac54ccf8bcb33ae262bce43d085affb77723492ee662263710d4008c9 nextcloud.logrotate
35cf156839215113b5d8fb8842b4c1e19a50be3c16be7048879fdd808674e4875dbacf3e2dd884fd182258595b7a137d7d3c2dc602a7ff5613c8b65fae0abe67 nextcloud.confd

View File

@ -1,12 +0,0 @@
--- a/lib/private/Config.php
+++ b/lib/private/Config.php
@@ -229,9 +229,6 @@
touch ($this->configFilePath);
$filePointer = fopen($this->configFilePath, 'r+');
- // Prevent others not to read the config
- chmod($this->configFilePath, 0640);
-
// File does not exist, this can happen when doing a fresh install
if(!is_resource ($filePointer)) {
// TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order

View File

@ -0,0 +1,44 @@
--- a/lib/private/Config.php
+++ b/lib/private/Config.php
@@ -229,9 +229,6 @@
touch ($this->configFilePath);
$filePointer = fopen($this->configFilePath, 'r+');
- // Prevent others not to read the config
- chmod($this->configFilePath, 0640);
-
// File does not exist, this can happen when doing a fresh install
if(!is_resource ($filePointer)) {
// TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order
--- a/lib/private/Log/File.php
+++ b/lib/private/Log/File.php
@@ -130,9 +130,6 @@
}
$entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR);
$handle = @fopen(self::$logFile, 'a');
- if ((fileperms(self::$logFile) & 0777) != 0640) {
- @chmod(self::$logFile, 0640);
- }
if ($handle) {
fwrite($handle, $entry."\n");
fclose($handle);
--- a/lib/private/TempManager.php
+++ b/lib/private/TempManager.php
@@ -94,7 +94,6 @@
if($postFix !== '') {
$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
touch($fileNameWithPostfix);
- chmod($fileNameWithPostfix, 0600);
$this->current[] = $fileNameWithPostfix;
return $fileNameWithPostfix;
}
--- a/lib/private/legacy/util.php
+++ b/lib/private/legacy/util.php
@@ -965,7 +965,6 @@
. ' cannot be listed by other users.');
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($perms, -1) !== '0') {
- chmod($dataDirectory, 0770);
clearstatcache();
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
if ($perms[2] !== '0') {