Fix: tmp file must be removed if error.

This commit is contained in:
Laurent Destailleur 2011-06-30 07:49:26 +00:00
parent 25f31d3eed
commit 80ed45badb

View File

@ -23,7 +23,7 @@
* \file htdocs/comm/action/class/actioncomm.class.php * \file htdocs/comm/action/class/actioncomm.class.php
* \ingroup commercial * \ingroup commercial
* \brief File of class to manage agenda events (actions) * \brief File of class to manage agenda events (actions)
* \version $Id$ * \version $Id: actioncomm.class.php,v 1.40 2011/06/30 07:49:26 eldy Exp $
*/ */
require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'); require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php');
require_once(DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'); require_once(DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php');
@ -675,7 +675,6 @@ class ActionComm extends CommonObject
// Create dir and define output file (definitive and temporary) // Create dir and define output file (definitive and temporary)
$result=create_exdir($conf->agenda->dir_temp); $result=create_exdir($conf->agenda->dir_temp);
$outputfile=$conf->agenda->dir_temp.'/'.$filename; $outputfile=$conf->agenda->dir_temp.'/'.$filename;
$outputfiletmp=tempnam($conf->agenda->dir_temp,'tmp'); // Temporary file (allow call of function by different threads
$result=0; $result=0;
@ -835,6 +834,10 @@ class ActionComm extends CommonObject
$desc.=$langs->convToOutputCharset(' ('.$mysoc->name.' - built by Dolibarr)'); $desc.=$langs->convToOutputCharset(' ('.$mysoc->name.' - built by Dolibarr)');
} }
// Create temp file
$outputfiletmp=tempnam($conf->agenda->dir_temp,'tmp'); // Temporary file (allow call of function by different threads
@chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
// Write file // Write file
if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfiletmp); if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfiletmp);
if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfiletmp); if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfiletmp);
@ -843,10 +846,15 @@ class ActionComm extends CommonObject
if ($result >= 0) if ($result >= 0)
{ {
if (rename($outputfiletmp,$outputfile)) $result=1; if (rename($outputfiletmp,$outputfile)) $result=1;
else $result=-1; else
{
dol_delete_file($outputfiletmp,0,1);
$result=-1;
}
} }
else else
{ {
dol_delete_file($outputfiletmp,0,1);
$langs->load("errors"); $langs->load("errors");
$this->error=$langs->trans("ErrorFailToCreateFile",$outputfile); $this->error=$langs->trans("ErrorFailToCreateFile",$outputfile);
} }