-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Create a checksum of the config file in memory #34146
Closed
ativarsoft
wants to merge
3
commits into
nextcloud:stable24
from
ativarsoft:mateus/stable24/optimization2
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ class Config { | |
protected $configFileName; | ||
/** @var bool */ | ||
protected $isReadOnly; | ||
/** @var int */ | ||
protected $lastChecksum; | ||
|
||
/** | ||
* @param string $configDir Path to the config dir, needs to end with '/' | ||
|
@@ -258,10 +260,23 @@ private function writeData() { | |
throw new HintException(sprintf('Configuration was not read or initialized correctly, not overwriting %s', $this->configFilePath)); | ||
} | ||
|
||
// This creates a checksum of the config file in memory. | ||
// The config file opcache code is only invalidated if the | ||
// config file data has been changed therefore all the other | ||
// code that depend on the the config file opcode will not | ||
// be recompiled. | ||
$data = var_export($this->cache, true); | ||
Check failure Code scanning / Psalm TaintedHtml
Detected tainted HTML
|
||
$currentChecksum = crc32($data); | ||
|
||
if ($this->getLastChecksum() == $currentChecksum) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will never be true, the checksum computed from file use the whole file content while the current one use only the data. |
||
return; | ||
|
||
$this->lastChecksum = $currentChecksum; | ||
|
||
// Create a php file ... | ||
$content = "<?php\n"; | ||
$content .= '$CONFIG = '; | ||
$content .= var_export($this->cache, true); | ||
$content .= $data; | ||
$content .= ";\n"; | ||
|
||
touch($this->configFilePath); | ||
|
@@ -304,4 +319,16 @@ private function checkReadOnly(): void { | |
'Unset "config_is_read_only" to allow changes to the config file.'); | ||
} | ||
} | ||
|
||
private function getLastChecksum(): int { | ||
if ($this->lastChecksum == null) { | ||
if (file_exists($this->configFilePath)) { | ||
$data = file_get_contents($this->configFilePath); | ||
$this->lastChecksum = crc32($data); | ||
} else { | ||
$this->lastChecksum = 0; | ||
} | ||
} | ||
return $this->lastChecksum; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Psalm
TaintedHtml