Skip to content

Commit 3a79ee2

Browse files
check if temp is writable
1 parent 5e7e3a3 commit 3a79ee2

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/Bolt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(private IConnection $connection)
3131
mkdir($_ENV['TEMP_DIR'], recursive: true);
3232
}
3333

34-
if (!getenv('BOLT_ANALYTICS_OPTOUT')) {
34+
if (!getenv('BOLT_ANALYTICS_OPTOUT') && is_writable($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR)) {
3535
if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
3636
mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
3737
}

src/protocol/AProtocol.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ protected function write(iterable $generator): void
7373

7474
private function track(): void
7575
{
76-
$file = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt';
77-
$count = file_exists($file) ? intval(file_get_contents($file)) : 0;
78-
file_put_contents($file, $count + 1);
76+
if (is_writable($_ENV['TEMP_DIR']. DIRECTORY_SEPARATOR)) {
77+
$file = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt';
78+
$count = file_exists($file) ? intval(file_get_contents($file)) : 0;
79+
file_put_contents($file, $count + 1);
80+
}
7981
}
8082

8183
/**

tests/protocol/ProtocolLayer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected function setUp(): void
105105
mkdir($_ENV['TEMP_DIR'], recursive: true);
106106
}
107107

108-
if (!getenv('BOLT_ANALYTICS_OPTOUT')) {
108+
if (!getenv('BOLT_ANALYTICS_OPTOUT') && is_writable($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR)) {
109109
if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) {
110110
mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics');
111111
}

0 commit comments

Comments
 (0)