Skip to content
Extraits de code Groupes Projets
Valider 03c966e3 rédigé par Fil's avatar Fil
Parcourir les fichiers

suite flock windows (ça marche ?)

parent 884584f9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -818,13 +818,15 @@ if (LOCK_UN!=3) { ...@@ -818,13 +818,15 @@ if (LOCK_UN!=3) {
define ('LOCK_UN', 3); define ('LOCK_UN', 3);
define ('LOCK_NB', 4); define ('LOCK_NB', 4);
} }
function test_flock ($dir, $fp=false) { function test_flock ($fichier, $fp=false) {
static $flock = array(); static $flock = array();
global $flag_flock; global $flag_flock;
if (!$flag_flock if (!$flag_flock
OR $os_serveur == 'windows') // sous win rename() plante avec fopen() OR $os_serveur == 'windows') // sous win rename() plante avec fopen()
return false; return false;
preg_match('|(.*)/([^/]*)$|', $fichier, $match);
$dir = $match[1];
if (!$dir) $dir = '.'; if (!$dir) $dir = '.';
// premier appel pour ce $dir ? // premier appel pour ce $dir ?
...@@ -849,10 +851,7 @@ function test_flock ($dir, $fp=false) { ...@@ -849,10 +851,7 @@ function test_flock ($dir, $fp=false) {
// Si flock ne marche pas dans ce repertoire ou chez cet hebergeur, // Si flock ne marche pas dans ce repertoire ou chez cet hebergeur,
// on renvoie OK pour ne pas bloquer // on renvoie OK pour ne pas bloquer
function spip_flock($filehandle, $mode, $fichier) { function spip_flock($filehandle, $mode, $fichier) {
preg_match('|(.*)/([^/]*)$|', $fichier, $match); if (!test_flock($fichier))
$dir = $match[1];
if (!test_flock($dir))
return true; return true;
$r = flock($filehandle, $mode); $r = flock($filehandle, $mode);
...@@ -946,7 +945,7 @@ function ecrire_fichier ($fichier, $contenu) { ...@@ -946,7 +945,7 @@ function ecrire_fichier ($fichier, $contenu) {
if ($ft = @$fopen($fichiertmp, 'wb')) { if ($ft = @$fopen($fichiertmp, 'wb')) {
// on en profite pour tester flock() // on en profite pour tester flock()
$flock = test_flock($dir, $ft); $flock = test_flock($fichiertmp, $ft);
$s = @$fputs($ft, $contenu, $a = strlen($contenu)); $s = @$fputs($ft, $contenu, $a = strlen($contenu));
@$fclose($ft); @$fclose($ft);
$ok = ($s == $a); $ok = ($s == $a);
...@@ -986,12 +985,14 @@ function supprimer_fichier ($fichier) { ...@@ -986,12 +985,14 @@ function supprimer_fichier ($fichier) {
if (!@file_exists($fichier)) if (!@file_exists($fichier))
return false; return false;
if (test_flock($fichier))
if ($fl = @fopen($fichier, 'r')) { if ($fl = @fopen($fichier, 'r')) {
while(!spip_flock($fl, LOCK_EX, $fichier)); while(!spip_flock($fl, LOCK_EX, $fichier));
spip_flock($fl, LOCK_UN, $fichier); spip_flock($fl, LOCK_UN, $fichier);
@fclose($fl); @fclose($fl);
@unlink($fichier);
} }
@unlink($fichier);
} }
// //
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter