From ffe48092fecde86474a194b05c5611edfd5fa593 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 5 Jun 2021 05:38:05 +0200 Subject: [PATCH 1/3] suppress error_log output of GoogleCloudStorage class in unit testing --- tst/Data/GoogleCloudStorageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tst/Data/GoogleCloudStorageTest.php b/tst/Data/GoogleCloudStorageTest.php index 91a5ca99..6905f04b 100644 --- a/tst/Data/GoogleCloudStorageTest.php +++ b/tst/Data/GoogleCloudStorageTest.php @@ -34,6 +34,7 @@ class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase // do not report E_NOTICE as fsouza/fake-gcs-server does not return a `generation` value in the response // which the Google Cloud Storage PHP library expects. error_reporting(E_ERROR | E_WARNING | E_PARSE); + ini_set('error_log', stream_get_meta_data(tmpfile())['uri']); $this->_model = GoogleCloudStorage::getInstance(array( 'bucket' => self::$_bucket->name(), 'prefix' => 'pastes', From edb8e5e078f2557716a17c8e92f91eb657d3b728 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 5 Jun 2021 05:48:17 +0200 Subject: [PATCH 2/3] handle edge cases with file locking: file needs to exist before it can be locked, fixes #803 --- lib/Persistence/AbstractPersistence.php | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/Persistence/AbstractPersistence.php b/lib/Persistence/AbstractPersistence.php index 0dcef50e..c96a0de3 100644 --- a/lib/Persistence/AbstractPersistence.php +++ b/lib/Persistence/AbstractPersistence.php @@ -90,12 +90,15 @@ abstract class AbstractPersistence } $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess'; if (!is_file($file)) { - $writtenBytes = @file_put_contents( - $file, - 'Require all denied' . PHP_EOL, - LOCK_EX - ); - if ($writtenBytes === false || $writtenBytes < 19) { + $writtenBytes = 0; + if ($fileCreated = @touch($file)) { + $writtenBytes = @file_put_contents( + $file, + 'Require all denied' . PHP_EOL, + LOCK_EX + ); + } + if ($fileCreated === false || $writtenBytes === false || $writtenBytes < 19) { throw new Exception('unable to write to file ' . $file, 11); } } @@ -114,9 +117,16 @@ abstract class AbstractPersistence protected static function _store($filename, $data) { self::_initialize(); - $file = self::$_path . DIRECTORY_SEPARATOR . $filename; - $writtenBytes = @file_put_contents($file, $data, LOCK_EX); - if ($writtenBytes === false || $writtenBytes < strlen($data)) { + $file = self::$_path . DIRECTORY_SEPARATOR . $filename; + $fileCreated = true; + $writtenBytes = 0; + if (!is_file($file)) { + $fileCreated = @touch($file); + } + if ($fileCreated) { + $writtenBytes = @file_put_contents($file, $data, LOCK_EX); + } + if ($fileCreated === false || $writtenBytes === false || $writtenBytes < strlen($data)) { throw new Exception('unable to write to file ' . $file, 13); } @chmod($file, 0640); // protect file access From abb2b90e9b13e09ee8853a6ff20f5617a4aadd94 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 5 Jun 2021 05:52:13 +0200 Subject: [PATCH 3/3] make StyleCI happy --- lib/Persistence/AbstractPersistence.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Persistence/AbstractPersistence.php b/lib/Persistence/AbstractPersistence.php index c96a0de3..489836da 100644 --- a/lib/Persistence/AbstractPersistence.php +++ b/lib/Persistence/AbstractPersistence.php @@ -117,8 +117,8 @@ abstract class AbstractPersistence protected static function _store($filename, $data) { self::_initialize(); - $file = self::$_path . DIRECTORY_SEPARATOR . $filename; - $fileCreated = true; + $file = self::$_path . DIRECTORY_SEPARATOR . $filename; + $fileCreated = true; $writtenBytes = 0; if (!is_file($file)) { $fileCreated = @touch($file);