diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-12-20 17:27:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-20 17:27:05 +0100 |
commit | c0cfd237ab1e7b8ac36e3d074ebafdf9e96d6e6a (patch) | |
tree | a9333af388f9921e6df8af890c6d3044430f42bc /lib | |
parent | a567f5d7b59382fc6b7fceab317936da80428c3f (diff) | |
parent | 52760a95d9d21c1e95968ff38a719f31f128ba5a (diff) | |
download | nextcloud-server-c0cfd237ab1e7b8ac36e3d074ebafdf9e96d6e6a.tar.gz nextcloud-server-c0cfd237ab1e7b8ac36e3d074ebafdf9e96d6e6a.zip |
Merge pull request #30299 from nextcloud/fix/log_files
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DB/Connection.php | 2 | ||||
-rw-r--r-- | lib/private/Memcache/Redis.php | 24 |
2 files changed, 15 insertions, 11 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 9efacb0f9ae..b8d1a747fa2 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -272,7 +272,7 @@ class Connection extends \Doctrine\DBAL\Connection { protected function logQueryToFile(string $sql): void { $logFile = $this->systemConfig->getValue('query_log_file', ''); - if ($logFile !== '' && is_writable($logFile)) { + if ($logFile !== '' && is_writable(dirname($logFile)) && (!file_exists($logFile) || is_writable($logFile))) { file_put_contents( $this->systemConfig->getValue('query_log_file', ''), $sql . "\n", diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index 74d8da187fe..63180dd8066 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -54,8 +54,12 @@ class Redis extends Cache implements IMemcacheTTL { return $this->prefix; } + private function logEnabled(): bool { + return $this->logFile !== '' && is_writable(dirname($this->logFile)) && (!file_exists($this->logFile) || is_writable($this->logFile)); + } + public function get($key) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::get::' . $key . "\n", @@ -72,7 +76,7 @@ class Redis extends Cache implements IMemcacheTTL { } public function set($key, $value, $ttl = 0) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::set::' . $key . '::' . $ttl . '::' . json_encode($value) . "\n", @@ -88,7 +92,7 @@ class Redis extends Cache implements IMemcacheTTL { } public function hasKey($key) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::hasKey::' . $key . "\n", @@ -100,7 +104,7 @@ class Redis extends Cache implements IMemcacheTTL { } public function remove($key) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::remove::' . $key . "\n", @@ -116,7 +120,7 @@ class Redis extends Cache implements IMemcacheTTL { } public function clear($prefix = '') { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::clear::' . $prefix . "\n", @@ -149,7 +153,7 @@ class Redis extends Cache implements IMemcacheTTL { if ($ttl !== 0 && is_int($ttl)) { $args['ex'] = $ttl; } - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::add::' . $key . '::' . $value . "\n", @@ -169,7 +173,7 @@ class Redis extends Cache implements IMemcacheTTL { * @return int | bool */ public function inc($key, $step = 1) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::inc::' . $key . "\n", @@ -188,7 +192,7 @@ class Redis extends Cache implements IMemcacheTTL { * @return int | bool */ public function dec($key, $step = 1) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::dec::' . $key . "\n", @@ -211,7 +215,7 @@ class Redis extends Cache implements IMemcacheTTL { * @return bool */ public function cas($key, $old, $new) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::cas::' . $key . "\n", @@ -241,7 +245,7 @@ class Redis extends Cache implements IMemcacheTTL { * @return bool */ public function cad($key, $old) { - if ($this->logFile !== '' && is_writable($this->logFile)) { + if ($this->logEnabled()) { file_put_contents( $this->logFile, $this->getNameSpace() . '::cad::' . $key . "\n", |