Skip to content

Commit

Permalink
#32221 Set permissions on log file creation instead of every write. (#…
Browse files Browse the repository at this point in the history
…32222)

* Set permissions on log file creation instead of every write.

* Code style fix and removed unnecessary else condition
  • Loading branch information
Michael Usher authored and DeepDiver1975 committed Oct 17, 2018
1 parent eadbb98 commit b71cc1c
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/private/Log/Owncloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ public static function init() {
* Fall back to default log file if specified logfile does not exist
* and can not be created.
*/
if (!\file_exists(self::$logFile)) {
if (!\is_writable(\dirname(self::$logFile))) {
self::$logFile = $defaultLogFile;
} else {
if (!\touch(self::$logFile)) {
self::$logFile = $defaultLogFile;
}
}
if (!self::createLogFile(self::$logFile)) {
self::$logFile = $defaultLogFile;
}
}

Expand Down Expand Up @@ -125,11 +119,11 @@ public static function writeExtra($app, $message, $level, $conditionalLogFile, $
if ($conditionalLogFile[0] !== '/') {
$conditionalLogFile = \OC::$server->getConfig()->getSystemValue('datadirectory') . "/" . $conditionalLogFile;
}
self::createLogFile($conditionalLogFile);
$handle = @\fopen($conditionalLogFile, 'a');
@\chmod($conditionalLogFile, 0640);
} else {
self::createLogFile(self::$logFile);
$handle = @\fopen(self::$logFile, 'a');
@\chmod(self::$logFile, 0640);
}
if ($handle) {
\fwrite($handle, $entry."\n");
Expand All @@ -143,6 +137,22 @@ public static function writeExtra($app, $message, $level, $conditionalLogFile, $
}
}

/**
* create a log file and chmod it to the correct permissions
* @param string $logFile
* @return boolean
*/
public static function createLogFile($logFile) {
if (\file_exists($logFile)) {
return true;
}
if (\is_writable(\dirname($logFile)) && \touch($logFile)) {
@\chmod($logFile, 0640);
return true;
}
return false;
}

/**
* @return string
*/
Expand Down

0 comments on commit b71cc1c

Please sign in to comment.