Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files:scan warning when NFD or incompatible encoding found #24341

Merged
merged 2 commits into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/files/command/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ protected function configure() {
);
}

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
Expand Down Expand Up @@ -126,14 +135,22 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
}
});
}
$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);
} catch (ForbiddenException $e) {
$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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/storage/smb.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getId() {
* @return string
*/
protected function buildPath($path) {
return Filesystem::normalizePath($this->root . '/' . $path);
return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
}

/**
Expand Down
21 changes: 8 additions & 13 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,12 @@ static public function hasUpdated($path, $time) {
* 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();
}
Expand All @@ -818,19 +819,13 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
}

//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;
Expand All @@ -856,7 +851,7 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
$path = substr($path, 0, -2);
}

$normalizedPath = $windows_drive_letter . $path;
$normalizedPath = $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath;

return $normalizedPath;
Expand Down