diff --git a/ecrire/inc/acces.php b/ecrire/inc/acces.php index 68b81f00e83844ab8868403df9a4a02dd38e40b6..4f895a40cdc199941cace046ec18682c851a542b 100644 --- a/ecrire/inc/acces.php +++ b/ecrire/inc/acces.php @@ -41,11 +41,13 @@ function creer_pass_aleatoire($longueur = 8, $sel = "") { return $pass; } -// -// Creer un identifiant aleatoire -// - -// http://doc.spip.org/@creer_uniqid +/** + * Creer un identifiant aleatoire + * + * http://doc.spip.org/@creer_uniqid + * + * @return string + */ function creer_uniqid() { static $seeded; diff --git a/ecrire/inc/distant.php b/ecrire/inc/distant.php index a3f2bfeacd02e049d5949cd837792b57c2faf8e5..be216ffc00df149fb0304d40bf48b27bdaae4722 100644 --- a/ecrire/inc/distant.php +++ b/ecrire/inc/distant.php @@ -70,9 +70,22 @@ function copie_locale($source, $mode = 'auto', $local = null){ return $local; if ($mode=='modif' OR !$t){ - $res = recuperer_page($source, $localrac, false, _COPIE_LOCALE_MAX_SIZE, '', '', false, $t ? filemtime($localrac) : ''); + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation + // et des eventuelles recuperations concurantes + include_spip("inc/acces"); + $localractmp = "$localrac.".creer_uniqid().".tmp"; + $res = recuperer_page($source, $localractmp, false, _COPIE_LOCALE_MAX_SIZE, '', '', false, $t ? filemtime($localrac) : ''); + if ($res) { + // si OK on supprime l'ancien fichier et on renomme + spip_log("copie_locale : recuperation $source sur $localractmp taille $res OK, renommage en $localrac"); + spip_unlink($localrac); + @rename($localractmp, $localrac); + } else { + // sinon on supprime le fichier temporaire qui a echoue et qui est sans doute corrompu... + spip_log("copie_locale : Echec recuperation $source sur $localractmp, fichier supprime",_LOG_INFO_IMPORTANTE); + spip_unlink($localractmp); + } if (!$res) return $t ? $local : false; -# spip_log ('ecrire copie locale '.$localrac." taille $res"); // pour une eventuelle indexation pipeline('post_edition',