Example #1
0
 protected function writeData()
 {
     $configFilePath = current($this->locator->getPathtoConfigFiles());
     // Create a php file ...
     $content = "<?php\n";
     $content .= '$CONFIG = ';
     $content .= var_export($this->cache, true);
     $content .= ";\n";
     touch($configFilePath);
     $filePointer = fopen($configFilePath, 'r+');
     // Prevent others not to read the config
     chmod($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', $configFilePath));
     }
     // Write the config and release the lock
     ftruncate($filePointer, 0);
     fwrite($filePointer, $content);
     fflush($filePointer);
     flock($filePointer, LOCK_UN);
     fclose($filePointer);
 }