/** * Writes the config file * * Saves the config to the config file. * * @throws HintException If the config file cannot be written to * @throws \Exception If no file lock can be acquired */ private function writeData() { // Create a php file ... $content = "<?php\n"; $content .= '$CONFIG = '; $content .= var_export($this->cache, true); $content .= ";\n"; touch($this->configFilePath); $filePointer = fopen($this->configFilePath, 'r+'); // Prevent others not to read the config chmod($this->configFilePath, 0640); // File does not exist, this can happen when doing a fresh install if (!is_resource($filePointer)) { $url = \OC_Helper::linkToDocs('admin-dir_permissions'); throw new HintException("Can't write into config directory!", 'This can usually be fixed by ' . '<a href="' . $url . '" target="_blank">giving the webserver write access to the config directory</a>.'); } // Try to acquire a file lock if (!flock($filePointer, LOCK_EX)) { throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); } // Write the config and release the lock ftruncate($filePointer, 0); fwrite($filePointer, $content); fflush($filePointer); flock($filePointer, LOCK_UN); fclose($filePointer); // Try invalidating the opcache just for the file we wrote... if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) { // But if that doesn't work, clear the whole cache. \OC_Util::clearOpcodeCache(); } }
/** * Writes the config file * * Saves the config to the config file. * * @throws HintException If the config file cannot be written to * @throws \Exception If no file lock can be acquired */ private function writeData() { // Create a php file ... $content = "<?php\n"; $content .= '$CONFIG = '; $content .= var_export($this->cache, true); $content .= ";\n"; touch($this->configFilePath); $filePointer = fopen($this->configFilePath, 'r+'); // Prevent others not to read the config chmod($this->configFilePath, 0640); // File does not exist, this can happen when doing a fresh install if (!is_resource($filePointer)) { // TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order // currently this breaks app routes but also could have other side effects especially during setup and exception handling $url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions'); throw new HintException("Can't write into config directory!", 'This can usually be fixed by ' . '<a href="' . $url . '" target="_blank" rel="noreferrer">giving the webserver write access to the config directory</a>.'); } // Try to acquire a file lock if (!flock($filePointer, LOCK_EX)) { throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); } // Write the config and release the lock ftruncate($filePointer, 0); fwrite($filePointer, $content); fflush($filePointer); flock($filePointer, LOCK_UN); fclose($filePointer); // Try invalidating the opcache just for the file we wrote... if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) { // But if that doesn't work, clear the whole cache. \OC_Util::clearOpcodeCache(); } }