diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-12-16 17:04:10 +0100 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2021-12-20 15:36:52 +0100 |
commit | 52760a95d9d21c1e95968ff38a719f31f128ba5a (patch) | |
tree | 565e2c829703941240d69186834bed3d16becb4d /lib/private/Memcache | |
parent | 0fc8b55bf1861336e263252e50b8b0c82e4dccbd (diff) | |
download | nextcloud-server-52760a95d9d21c1e95968ff38a719f31f128ba5a.tar.gz nextcloud-server-52760a95d9d21c1e95968ff38a719f31f128ba5a.zip |
Check if directoy is writable instead of possibly missing file
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/Memcache')
-rw-r--r-- | lib/private/Memcache/Redis.php | 24 |
1 files changed, 14 insertions, 10 deletions
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", |