Navigation Menu

Skip to content

Commit

Permalink
Now using io_savefile with locking and added header
Browse files Browse the repository at this point in the history
when saving plugin.local
  • Loading branch information
HakanS committed Sep 10, 2011
1 parent 48e46d8 commit 4645e48
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions inc/plugincontroller.class.php
Expand Up @@ -176,37 +176,33 @@ protected function checkRequire($files) {
function getCascade() {
return $this->plugin_cascade;
}

/**
* Save the current list of plugins
*/
function saveList() {
if(!empty($this->tmp_plugins)) {
//quick check to ensure rewrite is necessary
if($this->tmp_plugins != $this->tmp_bak) {
//Rebuild local for better check and saving
$local_plugins = $this->rebuildLocal();
//only write if the list has changed
if($local_plugins != $this->plugin_cascade['local']) {
$file = $this->last_local_config_file;
$out = "<?php\n";
foreach ($local_plugins as $plugin => $value) {
$out .= "\$plugins['$plugin'] = $value;\n";
}
// backup current file (remove any existing backup)
if (@file_exists($file)) {
if (@file_exists($file.'.bak')) @unlink($file.'.bak');
if (!io_rename($file, $file.'.bak')) return false;
}
//check if can open for writing, else restore
if (!$fh = @fopen($file, 'wb')) {
io_rename($file.'.bak', $file);// problem opening, restore the backup
return false;
}
@fwrite($fh, $out);
fclose($fh);
return true;
}
global $conf;

if (empty($this->tmp_plugins)) return false;
if ($this->tmp_plugins == $this->tmp_bak) return false;

// Rebuild list of local settings
$local_plugins = $this->rebuildLocal();
if($local_plugins != $this->plugin_cascade['local']) {
$file = $this->last_local_config_file;
$out = "<?php\n/*\n * Local plugin enable/disable settings\n * Auto-generated through plugin/extension manager\n */\n";
foreach ($local_plugins as $plugin => $value) {
$out .= "\$plugins['$plugin'] = $value;\n";
}
// backup current file (remove any existing backup)
if (@file_exists($file)) {
$backup = $file.'.bak';
if (@file_exists($backup)) @unlink($backup);
if (!@copy($file,$backup)) return false;
if ($conf['fperm']) chmod($backup, $conf['fperm']);
}
//check if can open for writing, else restore
return io_saveFile($file,$out);
}
return false;
}
Expand Down

0 comments on commit 4645e48

Please sign in to comment.