Skip to content

Commit

Permalink
Merge pull request #347 from nextcloud/drop-windows-foo
Browse files Browse the repository at this point in the history
Remove unneeded checks if it runs on a Windows machine
  • Loading branch information
LukasReschke authored Jul 11, 2016
2 parents 34c0b9d + 6ea77ab commit 0c1cf5f
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 269 deletions.
7 changes: 2 additions & 5 deletions apps/files_external/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ public function getBackends() {
$container->query('OCA\Files_External\Lib\Backend\Google'),
$container->query('OCA\Files_External\Lib\Backend\Swift'),
$container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
$container->query('OCA\Files_External\Lib\Backend\SMB'),
$container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
];

if (!\OC_Util::runningOnWindows()) {
$backends[] = $container->query('OCA\Files_External\Lib\Backend\SMB');
$backends[] = $container->query('OCA\Files_External\Lib\Backend\SMB_OC');
}

return $backends;
}

Expand Down
26 changes: 12 additions & 14 deletions console.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,18 @@ function exceptionHandler($exception) {

set_exception_handler('exceptionHandler');

if (!OC_Util::runningOnWindows()) {
if (!function_exists('posix_getuid')) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
exit(0);
}
$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
if ($user['name'] !== $configUser['name']) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
exit(0);
}
if (!function_exists('posix_getuid')) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
exit(0);
}
$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
if ($user['name'] !== $configUser['name']) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
exit(0);
}

$oldWorkingDir = getcwd();
Expand Down
24 changes: 11 additions & 13 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,17 @@
set_time_limit(0);

// the cron job must be executed with the right user
if (!OC_Util::runningOnWindows()) {
if (!function_exists('posix_getuid')) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
exit(0);
}
$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$SERVERROOT . '/config/config.php'));
if ($user['name'] !== $configUser['name']) {
echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Web server user: " . $configUser['name'] . PHP_EOL;
exit(0);
}
if (!function_exists('posix_getuid')) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
exit(0);
}
$user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$SERVERROOT . '/config/config.php'));
if ($user['name'] !== $configUser['name']) {
echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
echo "Current user: " . $user['name'] . PHP_EOL;
echo "Web server user: " . $configUser['name'] . PHP_EOL;
exit(0);
}

// We call ownCloud from the CLI (aka cron)
Expand Down
20 changes: 1 addition & 19 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,25 +489,7 @@ public function verifyPath($path, $fileName) {
}

// NOTE: $path will remain unverified for now
if (\OC_Util::runningOnWindows()) {
$this->verifyWindowsPath($fileName);
} else {
$this->verifyPosixPath($fileName);
}
}

/**
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
* @param string $fileName
* @throws InvalidPathException
*/
protected function verifyWindowsPath($fileName) {
$fileName = trim($fileName);
$this->scanForInvalidCharacters($fileName, "\\/<>:\"|?*");
$reservedNames = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9'];
if (in_array(strtoupper($fileName), $reservedNames)) {
throw new ReservedWordException();
}
$this->verifyPosixPath($fileName);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ protected function registerCoreProviders() {
}

if (count($checkImagick->queryFormats('PDF')) === 1) {
// Office previews are currently not supported on Windows
if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) {
if (\OC_Helper::is_function_enabled('shell_exec')) {
$officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null));

if (!$officeFound) {
Expand All @@ -324,9 +323,8 @@ protected function registerCoreProviders() {
}
}

// Video requires avconv or ffmpeg and is therefor
// currently not supported on Windows.
if (in_array('OC\Preview\Movie', $this->getEnabledDefaultProvider()) && !\OC_Util::runningOnWindows()) {
// Video requires avconv or ffmpeg
if (in_array('OC\Preview\Movie', $this->getEnabledDefaultProvider())) {
$avconvBinary = \OC_Helper::findBinaryPath('avconv');
$ffmpegBinary = ($avconvBinary) ? null : \OC_Helper::findBinaryPath('ffmpeg');

Expand Down
4 changes: 0 additions & 4 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ public function install($options) {
$trustedDomains = [$request->getInsecureServerHost()];
}

if (\OC_Util::runningOnWindows()) {
$dataDir = rtrim(realpath($dataDir), '\\');
}

//use sqlite3 when available, otherwise sqlite2 will be used.
if($dbType=='sqlite' and class_exists('SQLite3')) {
$dbType='sqlite3';
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public static function findBinaryPath($program) {
return $memcache->get($program);
}
$result = null;
if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) {
if (self::is_function_enabled('exec')) {
$exeSniffer = new ExecutableFinder();
// Returns null if nothing is found
$result = $exeSniffer->find($program);
Expand Down
33 changes: 12 additions & 21 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,22 +902,18 @@ public static function checkDatabaseVersion() {
public static function checkDataDirectoryPermissions($dataDirectory) {
$l = \OC::$server->getL10N('lib');
$errors = array();
if (self::runningOnWindows()) {
//TODO: permissions checks for windows hosts
} else {
$permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory'
. ' cannot be listed by other users.');
$permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory'
. ' 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 (substr($perms, -1) != '0') {
chmod($dataDirectory, 0770);
clearstatcache();
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($perms, 2, 1) != '0') {
$errors[] = array(
'error' => $l->t('Data directory (%s) is readable by other users', array($dataDirectory)),
'hint' => $permissionsModHint
);
}
if (substr($perms, 2, 1) != '0') {
$errors[] = array(
'error' => $l->t('Data directory (%s) is readable by other users', array($dataDirectory)),
'hint' => $permissionsModHint
);
}
}
return $errors;
Expand All @@ -933,7 +929,7 @@ public static function checkDataDirectoryPermissions($dataDirectory) {
public static function checkDataDirectoryValidity($dataDirectory) {
$l = \OC::$server->getL10N('lib');
$errors = [];
if (!self::runningOnWindows() && $dataDirectory[0] !== '/') {
if ($dataDirectory[0] !== '/') {
$errors[] = [
'error' => $l->t('Data directory (%s) must be an absolute path', [$dataDirectory]),
'hint' => $l->t('Check the value of "datadirectory" in your configuration')
Expand Down Expand Up @@ -1203,11 +1199,6 @@ public function isHtaccessWorking(\OCP\IConfig $config) {
* @return bool
*/
public static function isSetLocaleWorking() {
// setlocale test is pointless on Windows
if (OC_Util::runningOnWindows()) {
return true;
}

\Patchwork\Utf8\Bootup::initLocale();
if ('' === basename('§')) {
return false;
Expand Down
3 changes: 0 additions & 3 deletions settings/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@
$path = getenv('PATH');
$template->assign('getenvServerNotWorking', empty($path));

// warn if Windows is used
$template->assign('WindowsWarning', OC_Util::runningOnWindows());

// warn if outdated version of a memcache module is used
$caches = [
'apcu' => ['name' => $l->t('APCu'), 'version' => '4.0.6'],
Expand Down
9 changes: 0 additions & 9 deletions settings/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@
<?php
}

// Windows Warning
if ($_['WindowsWarning']) {
?>
<li>
<?php p($l->t('Your server is running on Microsoft Windows. We highly recommend Linux for optimal user experience.')); ?>
</li>
<?php
}

// Warning if memcache is outdated
foreach ($_['OutdatedCacheWarning'] as $php_module => $data) {
?>
Expand Down
8 changes: 0 additions & 8 deletions tests/lib/Archive/TARTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
use OC\Archive\TAR;

class TARTest extends TestBase {
protected function setUp() {
parent::setUp();

if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] tar archives are not supported on Windows');
}
}

protected function getExisting() {
$dir = \OC::$SERVERROOT . '/tests/data';
return new TAR($dir . '/data.tar.gz');
Expand Down
8 changes: 0 additions & 8 deletions tests/lib/Archive/ZIPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
use OC\Archive\ZIP;

class ZIPTest extends TestBase {
protected function setUp() {
parent::setUp();

if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] ');
}
}

protected function getExisting() {
$dir = \OC::$SERVERROOT . '/tests/data';
return new ZIP($dir . '/data.zip');
Expand Down
22 changes: 0 additions & 22 deletions tests/lib/Files/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,6 @@ public function testIsFileBlacklisted($path, $expected) {
$this->assertSame($expected, \OC\Files\Filesystem::isFileBlacklisted($path));
}

public function normalizePathWindowsAbsolutePathData() {
return array(
array('C:/', 'C:\\'),
array('C:/', 'C:\\', false),
array('C:/tests', 'C:\\tests'),
array('C:/tests', 'C:\\tests', false),
array('C:/tests', 'C:\\tests\\'),
array('C:/tests/', 'C:\\tests\\', false),
);
}

/**
* @dataProvider normalizePathWindowsAbsolutePathData
*/
public function testNormalizePathWindowsAbsolutePath($expected, $path, $stripTrailingSlash = true) {
if (!\OC_Util::runningOnWindows()) {
$this->markTestSkipped('This test is Windows only');
}

$this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash, true));
}

public function testNormalizePathUTF8() {
if (!class_exists('Patchwork\PHP\Shim\Normalizer')) {
$this->markTestSkipped('UTF8 normalizer Patchwork was not found');
Expand Down
Loading

0 comments on commit 0c1cf5f

Please sign in to comment.