Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blizzz
Copy link
Member

@blizzz blizzz commented Aug 28, 2024

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.

@blizzz
Copy link
Member Author

blizzz commented Aug 28, 2024

/backport to stable30

@blizzz
Copy link
Member Author

blizzz commented Aug 28, 2024

/backport to stable29

@blizzz
Copy link
Member Author

blizzz commented Aug 28, 2024

/backport to stable28

blizzz added 3 commits August 28, 2024 12:36
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]>
@@ -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.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new \Exception('Could not open config.php.');
throw new \Exception('Could not open config.php ' . $configFileName);

Copy link
Member

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?');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants