aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-05-02 09:41:12 +0200
committerMorris Jobke <hey@morrisjobke.de>2016-05-02 09:41:12 +0200
commit6b12f96b14ef4c560ae9be436caf2619739d74ae (patch)
tree8e147ec99cd933595acb0ee77ca86e8c097338e5
parenta323111bd1285f74aa405c240be86b5de5d0c502 (diff)
parent4326d73ff6dc4514163dbbe4164342cef8deba0a (diff)
downloadnextcloud-server-6b12f96b14ef4c560ae9be436caf2619739d74ae.tar.gz
nextcloud-server-6b12f96b14ef4c560ae9be436caf2619739d74ae.zip
Merge pull request #24341 from owncloud/scan-nfd-showwarning
Add files:scan warning when NFD or incompatible encoding found
-rw-r--r--apps/files/command/scan.php19
-rw-r--r--apps/files_external/lib/storage/smb.php2
-rw-r--r--lib/private/Files/Filesystem.php21
3 files changed, 27 insertions, 15 deletions
diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php
index f607b3e1af1..1ae04c585bb 100644
--- a/apps/files/command/scan.php
+++ b/apps/files/command/scan.php
@@ -89,6 +89,15 @@ class Scan extends Base {
);
}
+ public function checkScanWarning($fullPath, OutputInterface $output) {
+ $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath));
+ $path = basename($fullPath);
+
+ if ($normalizedPath !== $path) {
+ $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
+ }
+ }
+
protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
$scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
@@ -126,6 +135,12 @@ class Scan extends Base {
}
});
}
+ $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) {
+ $this->checkScanWarning($path, $output);
+ });
+ $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) {
+ $this->checkScanWarning($path, $output);
+ });
try {
$scanner->scan($path);
@@ -133,7 +148,9 @@ class Scan extends Base {
$output->writeln("<error>Home storage for user $user not writable</error>");
$output->writeln("Make sure you're running the scan command only as the user the web server runs as");
} catch (\Exception $e) {
- # exit the function if ctrl-c has been pressed
+ if ($e->getMessage() !== 'ctrl-c') {
+ $output->writeln('<error>Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>');
+ }
return;
}
}
diff --git a/apps/files_external/lib/storage/smb.php b/apps/files_external/lib/storage/smb.php
index 4249d13168c..868c52a63b4 100644
--- a/apps/files_external/lib/storage/smb.php
+++ b/apps/files_external/lib/storage/smb.php
@@ -100,7 +100,7 @@ class SMB extends \OC\Files\Storage\Common {
* @return string
*/
protected function buildPath($path) {
- return Filesystem::normalizePath($this->root . '/' . $path);
+ return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
}
/**
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php
index 39c5fd3ab4a..99c123ad1a1 100644
--- a/lib/private/Files/Filesystem.php
+++ b/lib/private/Files/Filesystem.php
@@ -789,11 +789,12 @@ class Filesystem {
* Fix common problems with a file path
*
* @param string $path
- * @param bool $stripTrailingSlash
- * @param bool $isAbsolutePath
+ * @param bool $stripTrailingSlash whether to strip the trailing slash
+ * @param bool $isAbsolutePath whether the given path is absolute
+ * @param bool $keepUnicode true to disable unicode normalization
* @return string
*/
- public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
+ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
if (is_null(self::$normalizedPathCache)) {
self::$normalizedPathCache = new CappedMemoryCache();
}
@@ -817,19 +818,13 @@ class Filesystem {
}
//normalize unicode if possible
- $path = \OC_Util::normalizeUnicode($path);
+ if (!$keepUnicode) {
+ $path = \OC_Util::normalizeUnicode($path);
+ }
//no windows style slashes
$path = str_replace('\\', '/', $path);
- // When normalizing an absolute path, we need to ensure that the drive-letter
- // is still at the beginning on windows
- $windows_drive_letter = '';
- if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') {
- $windows_drive_letter = substr($path, 0, 2);
- $path = substr($path, 2);
- }
-
//add leading slash
if ($path[0] !== '/') {
$path = '/' . $path;
@@ -855,7 +850,7 @@ class Filesystem {
$path = substr($path, 0, -2);
}
- $normalizedPath = $windows_drive_letter . $path;
+ $normalizedPath = $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath;
return $normalizedPath;