* NOTE! Previous locks are broken by this function */
function overwrite(&$rows) {
$this->unlock();
- $newfh = @fopen($this->filename, 'w');
+ $newfh = @fopen($this->filename .'.tmp', 'w');
if(!$newfh) {
- return $this->set_error("$file: " . _("Open failed"));
+ return $this->set_error($this->filename .'.tmp: '. _("Open failed"));
}
for($i = 0 ; $i < sizeof($rows) ; $i++) {
}
fclose($newfh);
+ copy( $this->filename .'.tmp' , $this->filename);
+ unlink( $this->filename .'.tmp');
$this->unlock();
$this->open(true);
return true;
}
} /* End of class abook_local_file */
-?>
\ No newline at end of file
+?>
$filename = getHashedFile($username, $data_dir, "$username.pref");
/* Open the file for writing, or else display an error to the user. */
- if(!$file = @fopen($filename, 'w'))
+ if(!$file = @fopen($filename.'.tmp', 'w'))
{
include_once(SM_PATH . 'functions/display_messages.php');
- logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) );
+ logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename.'.tmp') );
exit;
}
}
}
fclose($file);
+ copy($filename.'.tmp', $filename);
+ unlink($filename.'.tmp');
chmod($filename, 0600);
}
function setSig($data_dir, $username, $number, $value) {
$filename = getHashedFile($username, $data_dir, "$username.si$number");
/* Open the file for writing, or else display an error to the user. */
- if(!$file = @fopen($filename, 'w'))
+ if(!$file = @fopen($filename.'.tmp', 'w'))
{
include_once(SM_PATH . '/functions/display_messages.php' );
- logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) );
+ logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename.'.tmp') );
exit;
}
fwrite($file, $value);
fclose($file);
+ copy($filename.'.tmp',$filename);
+ unlink($filename.'.tmp');
}
/**