-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: lock config file when reading and writing #579
base: master
Are you sure you want to change the base?
Conversation
/backport to stable30 |
/backport to stable29 |
/backport to stable28 |
this is in accordance how the config files are handled in \OC\Config Signed-off-by: Arthur Schiwon <[email protected]>
Signed-off-by: Arthur Schiwon <[email protected]>
Signed-off-by: Arthur Schiwon <[email protected]>
42e81d8
to
e2f238d
Compare
@@ -89,9 +89,23 @@ public function __construct(string $baseDir) { | |||
if (!file_exists($configFileName)) { | |||
throw new \Exception('Could not find config.php. Is this file in the "updater" subfolder of Nextcloud?'); | |||
} | |||
$filePointer = @fopen($configFileName, 'r'); | |||
if ($filePointer === false) { | |||
throw new \Exception('Could not open config.php.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new \Exception('Could not open config.php.'); | |
throw new \Exception('Could not open config.php ' . $configFileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a fan of including the $configFileName
in the output (there are other spots too) since:
- full paths being on-hand helps make troubleshooting easier
- there may eventually be support for multiple config files at the Updater level (like there is already at Server)
@@ -89,9 +89,23 @@ public function __construct(string $baseDir) { | |||
if (!file_exists($configFileName)) { | |||
throw new \Exception('Could not find config.php. Is this file in the "updater" subfolder of Nextcloud?'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new \Exception('Could not find config.php. Is this file in the "updater" subfolder of Nextcloud?'); | |
throw new \Exception('Could not find config.php ' . $configFileName); |
throw new \Exception('Could not open config.php.'); | ||
} | ||
if (!flock($filePointer, LOCK_SH)) { | ||
throw new \Exception(sprintf('Could not acquire a shared lock on the config file')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new \Exception(sprintf('Could not acquire a shared lock on the config file')); | |
throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $configFileName)); |
nit: Generating the exceptions consistently would be preferred (i.e. all with sprintf or all without, but not both).
} | ||
|
||
try { | ||
require_once $configFileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: here we're using require_once
; below we're using require
(and it looks like in server
we use include
in the the Config
class.
this is in accordance how the config files are handled in \OC\Config
I successfully upgraded from 29.0.4 to 29.0.5 with updater.phar.