Skip to content
Snippets Groups Projects
Commit 739e8941 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Pb with config file backup

parent f3a56f8a
No related branches found
No related tags found
No related merge requests found
......@@ -208,8 +208,7 @@ if ($_POST["action"] == "set")
// Save old conf file on disk
if (file_exists("$conffile"))
{
$oldcontent = dol_openfile($conffile, 'r', '');
if (! dol_openfile($conffile.'.old', 'w', $oldcontent)) $error++;
@dol_copy($conffile, $conffile.'.old'); // We must ignore errors as an existing old file may alreday exists and not be replacable
}
$error+=write_conf_file($conffile);
......
......@@ -301,69 +301,14 @@ function dol_is_file($pathoffile)
$newpathoffile=dol_osencode($pathoffile);
return is_file($newpathoffile);
}
/**
* Reading or writing to a text file
*
* @param $file File to open or create
* @param $mode Mode to open file : r = returns the text of a file, or returns FALSE if the file isn't found
* w = creates or overrides a file with the text
* r+ = reads a text file, then writes the text to the end of the file
* @param $input String of text
* @return boolean True if ok, false if error
* Copy a file to another file
* @return boolean True if OK, false if KO
*/
function dol_openfile($file, $mode, $input)
function dol_copy($srcfile, $destfile)
{
if ($mode == "r")
{
if (file_exists($file))
{
$handle = fopen($file, "r");
$output = fread($handle, filesize($file));
return $output; // output file text
}
else
{
return false; // failed.
}
}
elseif ($mode == "w")
{
$handle = fopen($file, "w");
if (!fwrite($handle, $input))
{
return false; // failed.
}
else
{
return true; //success.
}
}
elseif ($mode == "r+")
{
if (file_exists($file) && isset($input))
{
$handle = fopen($file, "r+");
$read = fread($handle, filesize($file));
$data = $read.$input;
if (!fwrite($handle, $data))
{
return false; // failed.
}
else
{
return true; // success.
}
}
else
{
return false; // failed.
}
}
else
{
return false; // failed.
}
fclose($handle);
return @copy($srcfile, $destfile);
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment