Completed
Push — master ( f770ac...8397a1 )
by cam
11:16 queued 06:57
created
ecrire/inc/flock.php 1 patch
Indentation   +394 added lines, -394 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_TEST_FILE_EXISTS')) {
24
-	/** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
-	define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
24
+    /** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
+    define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
26 26
 }
27 27
 
28 28
 #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille)
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
31 31
 
32 32
 if (_SPIP_LOCK_MODE == 2) {
33
-	include_spip('inc/nfslock');
33
+    include_spip('inc/nfslock');
34 34
 }
35 35
 
36 36
 $GLOBALS['liste_verrous'] = array();
@@ -53,24 +53,24 @@  discard block
 block discarded – undo
53 53
  *     Ressource sur le fichier ouvert, sinon false.
54 54
  **/
55 55
 function spip_fopen_lock($fichier, $mode, $verrou) {
56
-	if (_SPIP_LOCK_MODE == 1) {
57
-		if ($fl = @fopen($fichier, $mode)) {
58
-			// verrou
59
-			@flock($fl, $verrou);
60
-		}
61
-
62
-		return $fl;
63
-	} elseif (_SPIP_LOCK_MODE == 2) {
64
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
-			$GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou);
66
-
67
-			return $fl;
68
-		} else {
69
-			return false;
70
-		}
71
-	}
72
-
73
-	return @fopen($fichier, $mode);
56
+    if (_SPIP_LOCK_MODE == 1) {
57
+        if ($fl = @fopen($fichier, $mode)) {
58
+            // verrou
59
+            @flock($fl, $verrou);
60
+        }
61
+
62
+        return $fl;
63
+    } elseif (_SPIP_LOCK_MODE == 2) {
64
+        if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
+            $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou);
66
+
67
+            return $fl;
68
+        } else {
69
+            return false;
70
+        }
71
+    }
72
+
73
+    return @fopen($fichier, $mode);
74 74
 }
75 75
 
76 76
 /**
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
  *     true si succès, false sinon.
86 86
  **/
87 87
 function spip_fclose_unlock($handle) {
88
-	if (_SPIP_LOCK_MODE == 1) {
89
-		@flock($handle, LOCK_UN);
90
-	} elseif (_SPIP_LOCK_MODE == 2) {
91
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
-		unset($GLOBALS['liste_verrous'][$handle]);
93
-	}
94
-
95
-	return @fclose($handle);
88
+    if (_SPIP_LOCK_MODE == 1) {
89
+        @flock($handle, LOCK_UN);
90
+    } elseif (_SPIP_LOCK_MODE == 2) {
91
+        spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
+        unset($GLOBALS['liste_verrous'][$handle]);
93
+    }
94
+
95
+    return @fclose($handle);
96 96
 }
97 97
 
98 98
 
@@ -106,23 +106,23 @@  discard block
 block discarded – undo
106 106
  *     Contenu du fichier
107 107
  **/
108 108
 function spip_file_get_contents($fichier) {
109
-	if (substr($fichier, -3) != '.gz') {
110
-		if (function_exists('file_get_contents')) {
111
-			// quand on est sous windows on ne sait pas si file_get_contents marche
112
-			// on essaye : si ca retourne du contenu alors c'est bon
113
-			// sinon on fait un file() pour avoir le coeur net
114
-			$contenu = @file_get_contents($fichier);
115
-			if (!$contenu and _OS_SERVEUR == 'windows') {
116
-				$contenu = @file($fichier);
117
-			}
118
-		} else {
119
-			$contenu = @file($fichier);
120
-		}
121
-	} else {
122
-		$contenu = @gzfile($fichier);
123
-	}
124
-
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
109
+    if (substr($fichier, -3) != '.gz') {
110
+        if (function_exists('file_get_contents')) {
111
+            // quand on est sous windows on ne sait pas si file_get_contents marche
112
+            // on essaye : si ca retourne du contenu alors c'est bon
113
+            // sinon on fait un file() pour avoir le coeur net
114
+            $contenu = @file_get_contents($fichier);
115
+            if (!$contenu and _OS_SERVEUR == 'windows') {
116
+                $contenu = @file($fichier);
117
+            }
118
+        } else {
119
+            $contenu = @file($fichier);
120
+        }
121
+    } else {
122
+        $contenu = @gzfile($fichier);
123
+    }
124
+
125
+    return is_array($contenu) ? join('', $contenu) : (string)$contenu;
126 126
 }
127 127
 
128 128
 
@@ -147,48 +147,48 @@  discard block
 block discarded – undo
147 147
  *     true si l'opération a réussie, false sinon.
148 148
  **/
149 149
 function lire_fichier($fichier, &$contenu, $options = array()) {
150
-	$contenu = '';
151
-	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
-	// economisons donc les acces disque, sauf chez free qui rale pour un rien
153
-	if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
-		return false;
155
-	}
156
-
157
-	#spip_timer('lire_fichier');
158
-
159
-	// pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
-	if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
-		// lire le fichier avant tout
162
-		$contenu = spip_file_get_contents($fichier);
163
-
164
-		// le fichier a-t-il ete supprime par le locker ?
165
-		// on ne verifie que si la tentative de lecture a echoue
166
-		// pour discriminer un contenu vide d'un fichier absent
167
-		// et eviter un acces disque
168
-		if (!$contenu and !@file_exists($fichier)) {
169
-			spip_fclose_unlock($fl);
170
-
171
-			return false;
172
-		}
173
-
174
-		// liberer le verrou
175
-		spip_fclose_unlock($fl);
176
-
177
-		// Verifications
178
-		$ok = true;
179
-		if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
181
-		}
182
-
183
-		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
-		if (!$ok) {
185
-			spip_log("echec lecture $fichier");
186
-		}
187
-
188
-		return $ok;
189
-	}
190
-
191
-	return false;
150
+    $contenu = '';
151
+    // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
+    // economisons donc les acces disque, sauf chez free qui rale pour un rien
153
+    if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
+        return false;
155
+    }
156
+
157
+    #spip_timer('lire_fichier');
158
+
159
+    // pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
+    if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
+        // lire le fichier avant tout
162
+        $contenu = spip_file_get_contents($fichier);
163
+
164
+        // le fichier a-t-il ete supprime par le locker ?
165
+        // on ne verifie que si la tentative de lecture a echoue
166
+        // pour discriminer un contenu vide d'un fichier absent
167
+        // et eviter un acces disque
168
+        if (!$contenu and !@file_exists($fichier)) {
169
+            spip_fclose_unlock($fl);
170
+
171
+            return false;
172
+        }
173
+
174
+        // liberer le verrou
175
+        spip_fclose_unlock($fl);
176
+
177
+        // Verifications
178
+        $ok = true;
179
+        if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
+            $ok &= (preg_match(",[?]>\n?$,", $contenu));
181
+        }
182
+
183
+        #spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
+        if (!$ok) {
185
+            spip_log("echec lecture $fichier");
186
+        }
187
+
188
+        return $ok;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 
@@ -216,85 +216,85 @@  discard block
 block discarded – undo
216 216
  **/
217 217
 function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) {
218 218
 
219
-	#spip_timer('ecrire_fichier');
220
-
221
-	// verrouiller le fichier destination
222
-	if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
-		// ecrire les donnees, compressees le cas echeant
224
-		// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
-		// de le recreer si le locker qui nous precede l'avait supprime...)
226
-		if (substr($fichier, -3) == '.gz') {
227
-			$contenu = gzencode($contenu);
228
-		}
229
-		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
-		// pour etre sur d'avoir une operation atomique
231
-		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
-		// sauf sous wintruc ou ca ne marche pas
233
-		$ok = false;
234
-		if ($truncate and _OS_SERVEUR != 'windows') {
235
-			if (!function_exists('creer_uniqid')) {
236
-				include_spip('inc/acces');
237
-			}
238
-			$id = creer_uniqid();
239
-			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
-				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
-				$ok = ($s == $a);
243
-				spip_fclose_unlock($fp2);
244
-				spip_fclose_unlock($fp);
245
-				// unlink direct et pas spip_unlink car on avait deja le verrou
246
-				// a priori pas besoin car rename ecrase la cible
247
-				// @unlink($fichier);
248
-				// le rename aussitot, atomique quand on est pas sous windows
249
-				// au pire on arrive en second en cas de concourance, et le rename echoue
250
-				// --> on a la version de l'autre process qui doit etre identique
251
-				@rename("$fichier.$id", $fichier);
252
-				// precaution en cas d'echec du rename
253
-				if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
-					@unlink("$fichier.$id");
255
-				}
256
-				if ($ok) {
257
-					$ok = file_exists($fichier);
258
-				}
259
-			} else // echec mais penser a fermer ..
260
-			{
261
-				spip_fclose_unlock($fp);
262
-			}
263
-		}
264
-		// sinon ou si methode precedente a echoueee
265
-		// on se rabat sur la methode ancienne
266
-		if (!$ok) {
267
-			// ici on est en ajout ou sous windows, cas desespere
268
-			if ($truncate) {
269
-				@ftruncate($fp, 0);
270
-			}
271
-			$s = @fputs($fp, $contenu, $a = strlen($contenu));
272
-
273
-			$ok = ($s == $a);
274
-			spip_fclose_unlock($fp);
275
-		}
276
-
277
-		// liberer le verrou et fermer le fichier
278
-		@chmod($fichier, _SPIP_CHMOD & 0666);
279
-		if ($ok) {
280
-			if (strpos($fichier, ".php") !== false) {
281
-				spip_clear_opcode_cache(realpath($fichier));
282
-			}
283
-
284
-			return $ok;
285
-		}
286
-	}
287
-
288
-	if (!$ignorer_echec) {
289
-		include_spip('inc/autoriser');
290
-		if (autoriser('chargerftp')) {
291
-			raler_fichier($fichier);
292
-		}
293
-		spip_unlink($fichier);
294
-	}
295
-	spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
-
297
-	return false;
219
+    #spip_timer('ecrire_fichier');
220
+
221
+    // verrouiller le fichier destination
222
+    if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
+        // ecrire les donnees, compressees le cas echeant
224
+        // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
+        // de le recreer si le locker qui nous precede l'avait supprime...)
226
+        if (substr($fichier, -3) == '.gz') {
227
+            $contenu = gzencode($contenu);
228
+        }
229
+        // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
+        // pour etre sur d'avoir une operation atomique
231
+        // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
+        // sauf sous wintruc ou ca ne marche pas
233
+        $ok = false;
234
+        if ($truncate and _OS_SERVEUR != 'windows') {
235
+            if (!function_exists('creer_uniqid')) {
236
+                include_spip('inc/acces');
237
+            }
238
+            $id = creer_uniqid();
239
+            // on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
+            if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
+                $s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
+                $ok = ($s == $a);
243
+                spip_fclose_unlock($fp2);
244
+                spip_fclose_unlock($fp);
245
+                // unlink direct et pas spip_unlink car on avait deja le verrou
246
+                // a priori pas besoin car rename ecrase la cible
247
+                // @unlink($fichier);
248
+                // le rename aussitot, atomique quand on est pas sous windows
249
+                // au pire on arrive en second en cas de concourance, et le rename echoue
250
+                // --> on a la version de l'autre process qui doit etre identique
251
+                @rename("$fichier.$id", $fichier);
252
+                // precaution en cas d'echec du rename
253
+                if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
+                    @unlink("$fichier.$id");
255
+                }
256
+                if ($ok) {
257
+                    $ok = file_exists($fichier);
258
+                }
259
+            } else // echec mais penser a fermer ..
260
+            {
261
+                spip_fclose_unlock($fp);
262
+            }
263
+        }
264
+        // sinon ou si methode precedente a echoueee
265
+        // on se rabat sur la methode ancienne
266
+        if (!$ok) {
267
+            // ici on est en ajout ou sous windows, cas desespere
268
+            if ($truncate) {
269
+                @ftruncate($fp, 0);
270
+            }
271
+            $s = @fputs($fp, $contenu, $a = strlen($contenu));
272
+
273
+            $ok = ($s == $a);
274
+            spip_fclose_unlock($fp);
275
+        }
276
+
277
+        // liberer le verrou et fermer le fichier
278
+        @chmod($fichier, _SPIP_CHMOD & 0666);
279
+        if ($ok) {
280
+            if (strpos($fichier, ".php") !== false) {
281
+                spip_clear_opcode_cache(realpath($fichier));
282
+            }
283
+
284
+            return $ok;
285
+        }
286
+    }
287
+
288
+    if (!$ignorer_echec) {
289
+        include_spip('inc/autoriser');
290
+        if (autoriser('chargerftp')) {
291
+            raler_fichier($fichier);
292
+        }
293
+        spip_unlink($fichier);
294
+    }
295
+    spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
+
297
+    return false;
298 298
 }
299 299
 
300 300
 /**
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
314 314
  *     Écriture avec troncation ?
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317
-	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
-	}
320
-	$contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
317
+    if (substr($fichier, -4) !== '.php') {
318
+        spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
+    }
320
+    $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
321 321
 
322
-	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
322
+    return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
324 324
 
325 325
 
@@ -330,23 +330,23 @@  discard block
 block discarded – undo
330 330
  * @return bool
331 331
  */
332 332
 function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force=false, $use_copy=false) {
333
-	$fichier_tmp = $fichier . '.last';
334
-	if (!ecrire_fichier($fichier_tmp, $contenu, true)){
335
-		return false;
336
-	}
337
-	if ($force
338
-	  or !file_exists($fichier)
339
-		or md5_file($fichier) != md5_file($fichier_tmp)) {
340
-		if ($use_copy) {
341
-			@copy($fichier_tmp, $fichier);
342
-		}
343
-		else {
344
-			@rename($fichier_tmp, $fichier);
345
-		}
346
-		// eviter que PHP ne reserve le vieux timestamp
347
-		clearstatcache(true, $fichier);
348
-	}
349
-	return true;
333
+    $fichier_tmp = $fichier . '.last';
334
+    if (!ecrire_fichier($fichier_tmp, $contenu, true)){
335
+        return false;
336
+    }
337
+    if ($force
338
+      or !file_exists($fichier)
339
+        or md5_file($fichier) != md5_file($fichier_tmp)) {
340
+        if ($use_copy) {
341
+            @copy($fichier_tmp, $fichier);
342
+        }
343
+        else {
344
+            @rename($fichier_tmp, $fichier);
345
+        }
346
+        // eviter que PHP ne reserve le vieux timestamp
347
+        clearstatcache(true, $fichier);
348
+    }
349
+    return true;
350 350
 }
351 351
 
352 352
 
@@ -367,11 +367,11 @@  discard block
 block discarded – undo
367 367
  *     true si l'opération a réussie, false sinon.
368 368
  */
369 369
 function lire_fichier_securise($fichier, &$contenu, $options = array()) {
370
-	if ($res = lire_fichier($fichier, $contenu, $options)) {
371
-		$contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n"));
372
-	}
370
+    if ($res = lire_fichier($fichier, $contenu, $options)) {
371
+        $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n"));
372
+    }
373 373
 
374
-	return $res;
374
+    return $res;
375 375
 }
376 376
 
377 377
 /**
@@ -386,20 +386,20 @@  discard block
 block discarded – undo
386 386
  *     Chemin du fichier
387 387
  **/
388 388
 function raler_fichier($fichier) {
389
-	include_spip('inc/minipres');
390
-	$dir = dirname($fichier);
391
-	http_status(401);
392
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
393
-		. _T('texte_inc_meta_1', array('fichier' => $fichier))
394
-		. " <a href='"
395
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
396
-		. "'>"
397
-		. _T('texte_inc_meta_2')
398
-		. "</a> "
399
-		. _T('texte_inc_meta_3',
400
-			array('repertoire' => joli_repertoire($dir)))
401
-		. "</h4>\n");
402
-	exit;
389
+    include_spip('inc/minipres');
390
+    $dir = dirname($fichier);
391
+    http_status(401);
392
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
393
+        . _T('texte_inc_meta_1', array('fichier' => $fichier))
394
+        . " <a href='"
395
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
396
+        . "'>"
397
+        . _T('texte_inc_meta_2')
398
+        . "</a> "
399
+        . _T('texte_inc_meta_3',
400
+            array('repertoire' => joli_repertoire($dir)))
401
+        . "</h4>\n");
402
+    exit;
403 403
 }
404 404
 
405 405
 
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
  *     - true si récent, false sinon
415 415
  */
416 416
 function jeune_fichier($fichier, $n) {
417
-	if (!file_exists($fichier)) {
418
-		return false;
419
-	}
420
-	if (!$c = @filemtime($fichier)) {
421
-		return false;
422
-	}
423
-
424
-	return (time() - $n <= $c);
417
+    if (!file_exists($fichier)) {
418
+        return false;
419
+    }
420
+    if (!$c = @filemtime($fichier)) {
421
+        return false;
422
+    }
423
+
424
+    return (time() - $n <= $c);
425 425
 }
426 426
 
427 427
 /**
@@ -436,22 +436,22 @@  discard block
 block discarded – undo
436 436
  *     - false si on n'arrive pas poser le verrou ou si la suppression échoue
437 437
  */
438 438
 function supprimer_fichier($fichier, $lock = true) {
439
-	if (!@file_exists($fichier)) {
440
-		return true;
441
-	}
442
-
443
-	if ($lock) {
444
-		// verrouiller le fichier destination
445
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
446
-			return false;
447
-		}
448
-
449
-		// liberer le verrou
450
-		spip_fclose_unlock($fp);
451
-	}
452
-
453
-	// supprimer
454
-	return @unlink($fichier);
439
+    if (!@file_exists($fichier)) {
440
+        return true;
441
+    }
442
+
443
+    if ($lock) {
444
+        // verrouiller le fichier destination
445
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
446
+            return false;
447
+        }
448
+
449
+        // liberer le verrou
450
+        spip_fclose_unlock($fp);
451
+    }
452
+
453
+    // supprimer
454
+    return @unlink($fichier);
455 455
 }
456 456
 
457 457
 /**
@@ -461,12 +461,12 @@  discard block
 block discarded – undo
461 461
  *     Chemin du fichier
462 462
  */
463 463
 function spip_unlink($f) {
464
-	if (!is_dir($f)) {
465
-		supprimer_fichier($f, false);
466
-	} else {
467
-		@unlink("$f/.ok");
468
-		@rmdir($f);
469
-	}
464
+    if (!is_dir($f)) {
465
+        supprimer_fichier($f, false);
466
+    } else {
467
+        @unlink("$f/.ok");
468
+        @rmdir($f);
469
+    }
470 470
 }
471 471
 
472 472
 /**
@@ -480,26 +480,26 @@  discard block
 block discarded – undo
480 480
  *   The absolute path of the PHP file to invalidate.
481 481
  */
482 482
 function spip_clear_opcode_cache($filepath) {
483
-	clearstatcache(true, $filepath);
484
-
485
-	// Zend OPcache
486
-	if (function_exists('opcache_invalidate')) {
487
-		$invalidate = @opcache_invalidate($filepath, true);
488
-		// si l'invalidation a echoue lever un flag
489
-		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
490
-			define('_spip_attend_invalidation_opcode_cache',true);
491
-		}
492
-	} elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
493
-		// n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
494
-		define('_spip_attend_invalidation_opcode_cache',true);
495
-	}
496
-	// APC.
497
-	if (function_exists('apc_delete_file')) {
498
-		// apc_delete_file() throws a PHP warning in case the specified file was
499
-		// not compiled yet.
500
-		// @see http://php.net/apc-delete-file
501
-		@apc_delete_file($filepath);
502
-	}
483
+    clearstatcache(true, $filepath);
484
+
485
+    // Zend OPcache
486
+    if (function_exists('opcache_invalidate')) {
487
+        $invalidate = @opcache_invalidate($filepath, true);
488
+        // si l'invalidation a echoue lever un flag
489
+        if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
490
+            define('_spip_attend_invalidation_opcode_cache',true);
491
+        }
492
+    } elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
493
+        // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
494
+        define('_spip_attend_invalidation_opcode_cache',true);
495
+    }
496
+    // APC.
497
+    if (function_exists('apc_delete_file')) {
498
+        // apc_delete_file() throws a PHP warning in case the specified file was
499
+        // not compiled yet.
500
+        // @see http://php.net/apc-delete-file
501
+        @apc_delete_file($filepath);
502
+    }
503 503
 }
504 504
 
505 505
 /**
@@ -522,24 +522,24 @@  discard block
 block discarded – undo
522 522
  *
523 523
  */
524 524
 function spip_attend_invalidation_opcode_cache($timestamp = null) {
525
-	if (function_exists('opcache_get_configuration')
526
-		and @ini_get('opcache.enable')
527
-		and @ini_get('opcache.validate_timestamps')
528
-		and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
529
-		and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
530
-	) {
531
-		$wait = $duree + 1;
532
-		if ($timestamp) {
533
-			$wait -= (time() - $timestamp);
534
-			if ($wait<0) {
535
-				$wait = 0;
536
-			}
537
-		}
538
-		spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
539
-		if ($wait) {
540
-			sleep($duree + 1);
541
-		}
542
-	}
525
+    if (function_exists('opcache_get_configuration')
526
+        and @ini_get('opcache.enable')
527
+        and @ini_get('opcache.validate_timestamps')
528
+        and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
529
+        and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
530
+    ) {
531
+        $wait = $duree + 1;
532
+        if ($timestamp) {
533
+            $wait -= (time() - $timestamp);
534
+            if ($wait<0) {
535
+                $wait = 0;
536
+            }
537
+        }
538
+        spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
539
+        if ($wait) {
540
+            sleep($duree + 1);
541
+        }
542
+    }
543 543
 }
544 544
 
545 545
 
@@ -552,26 +552,26 @@  discard block
 block discarded – undo
552 552
  * @return bool Suppression reussie.
553 553
  */
554 554
 function supprimer_repertoire($dir) {
555
-	if (!file_exists($dir)) {
556
-		return true;
557
-	}
558
-	if (!is_dir($dir) || is_link($dir)) {
559
-		return @unlink($dir);
560
-	}
561
-
562
-	foreach (scandir($dir) as $item) {
563
-		if ($item == '.' || $item == '..') {
564
-			continue;
565
-		}
566
-		if (!supprimer_repertoire($dir . "/" . $item)) {
567
-			@chmod($dir . "/" . $item, 0777);
568
-			if (!supprimer_repertoire($dir . "/" . $item)) {
569
-				return false;
570
-			}
571
-		};
572
-	}
573
-
574
-	return @rmdir($dir);
555
+    if (!file_exists($dir)) {
556
+        return true;
557
+    }
558
+    if (!is_dir($dir) || is_link($dir)) {
559
+        return @unlink($dir);
560
+    }
561
+
562
+    foreach (scandir($dir) as $item) {
563
+        if ($item == '.' || $item == '..') {
564
+            continue;
565
+        }
566
+        if (!supprimer_repertoire($dir . "/" . $item)) {
567
+            @chmod($dir . "/" . $item, 0777);
568
+            if (!supprimer_repertoire($dir . "/" . $item)) {
569
+                return false;
570
+            }
571
+        };
572
+    }
573
+
574
+    return @rmdir($dir);
575 575
 }
576 576
 
577 577
 
@@ -600,57 +600,57 @@  discard block
 block discarded – undo
600 600
  *     Chemin du répertoire créé.
601 601
  **/
602 602
 function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
603
-	static $dirs = array();
604
-
605
-	$base = str_replace("//", "/", $base);
606
-
607
-	# suppr le dernier caractere si c'est un /
608
-	$base = rtrim($base, '/');
609
-
610
-	if (!strlen($subdir)) {
611
-		$n = strrpos($base, "/");
612
-		if ($n === false) {
613
-			return $nobase ? '' : ($base . '/');
614
-		}
615
-		$subdir = substr($base, $n + 1);
616
-		$base = substr($base, 0, $n + 1);
617
-	} else {
618
-		$base .= '/';
619
-		$subdir = str_replace("/", "", $subdir);
620
-	}
621
-
622
-	$baseaff = $nobase ? '' : $base;
623
-	if (isset($dirs[$base . $subdir])) {
624
-		return $baseaff . $dirs[$base . $subdir];
625
-	}
626
-
627
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
628
-
629
-	if (file_exists("$path/.ok")) {
630
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
631
-	}
632
-
633
-	@mkdir($path, _SPIP_CHMOD);
634
-	@chmod($path, _SPIP_CHMOD);
635
-
636
-	if (is_dir($path) && is_writable($path)) {
637
-		@touch("$path/.ok");
638
-		spip_log("creation $base$subdir/");
639
-
640
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
641
-	}
642
-
643
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
644
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
645
-	spip_log("echec creation $base${subdir}");
646
-	if ($tantpis) {
647
-		return '';
648
-	}
649
-	if (!_DIR_RESTREINT) {
650
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
651
-	}
652
-	$base .= $subdir;
653
-	raler_fichier($base . '/.ok');
603
+    static $dirs = array();
604
+
605
+    $base = str_replace("//", "/", $base);
606
+
607
+    # suppr le dernier caractere si c'est un /
608
+    $base = rtrim($base, '/');
609
+
610
+    if (!strlen($subdir)) {
611
+        $n = strrpos($base, "/");
612
+        if ($n === false) {
613
+            return $nobase ? '' : ($base . '/');
614
+        }
615
+        $subdir = substr($base, $n + 1);
616
+        $base = substr($base, 0, $n + 1);
617
+    } else {
618
+        $base .= '/';
619
+        $subdir = str_replace("/", "", $subdir);
620
+    }
621
+
622
+    $baseaff = $nobase ? '' : $base;
623
+    if (isset($dirs[$base . $subdir])) {
624
+        return $baseaff . $dirs[$base . $subdir];
625
+    }
626
+
627
+    $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
628
+
629
+    if (file_exists("$path/.ok")) {
630
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
631
+    }
632
+
633
+    @mkdir($path, _SPIP_CHMOD);
634
+    @chmod($path, _SPIP_CHMOD);
635
+
636
+    if (is_dir($path) && is_writable($path)) {
637
+        @touch("$path/.ok");
638
+        spip_log("creation $base$subdir/");
639
+
640
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
641
+    }
642
+
643
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
644
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
645
+    spip_log("echec creation $base${subdir}");
646
+    if ($tantpis) {
647
+        return '';
648
+    }
649
+    if (!_DIR_RESTREINT) {
650
+        $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
651
+    }
652
+    $base .= $subdir;
653
+    raler_fichier($base . '/.ok');
654 654
 }
655 655
 
656 656
 
@@ -683,51 +683,51 @@  discard block
 block discarded – undo
683 683
  *     Chemins des fichiers trouvés.
684 684
  **/
685 685
 function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) {
686
-	$nbfiles = 0;
687
-	if ($pattern == -1) {
688
-		$pattern = "^$dir";
689
-	}
690
-	$fichiers = array();
691
-	// revenir au repertoire racine si on a recu dossier/truc
692
-	// pour regarder dossier/truc/ ne pas oublier le / final
693
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
694
-	if ($dir == '') {
695
-		$dir = '.';
696
-	}
697
-
698
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
699
-		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
700
-			if ($f[0] != '.' # ignorer . .. .svn etc
701
-				and $f != 'CVS'
702
-				and $f != 'remove.txt'
703
-				and is_readable($f = "$dir/$f")
704
-			) {
705
-				if (is_file($f)) {
706
-					if (preg_match(";$pattern;iS", $f)) {
707
-						$fichiers[] = $f;
708
-						$nbfiles++;
709
-					}
710
-				} else {
711
-					if (is_dir($f) and is_array($recurs)) {
712
-						$rp = @realpath($f);
713
-						if (!is_string($rp) or !strlen($rp)) {
714
-							$rp = $f;
715
-						} # realpath n'est peut etre pas autorise
716
-						if (!isset($recurs[$rp])) {
717
-							$recurs[$rp] = true;
718
-							$beginning = $fichiers;
719
-							$end = preg_files("$f/", $pattern,
720
-								$maxfiles - $nbfiles, $recurs);
721
-							$fichiers = array_merge((array)$beginning, (array)$end);
722
-							$nbfiles = count($fichiers);
723
-						}
724
-					}
725
-				}
726
-			}
727
-		}
728
-		closedir($d);
729
-	}
730
-	sort($fichiers);
731
-
732
-	return $fichiers;
686
+    $nbfiles = 0;
687
+    if ($pattern == -1) {
688
+        $pattern = "^$dir";
689
+    }
690
+    $fichiers = array();
691
+    // revenir au repertoire racine si on a recu dossier/truc
692
+    // pour regarder dossier/truc/ ne pas oublier le / final
693
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
694
+    if ($dir == '') {
695
+        $dir = '.';
696
+    }
697
+
698
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
699
+        while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
700
+            if ($f[0] != '.' # ignorer . .. .svn etc
701
+                and $f != 'CVS'
702
+                and $f != 'remove.txt'
703
+                and is_readable($f = "$dir/$f")
704
+            ) {
705
+                if (is_file($f)) {
706
+                    if (preg_match(";$pattern;iS", $f)) {
707
+                        $fichiers[] = $f;
708
+                        $nbfiles++;
709
+                    }
710
+                } else {
711
+                    if (is_dir($f) and is_array($recurs)) {
712
+                        $rp = @realpath($f);
713
+                        if (!is_string($rp) or !strlen($rp)) {
714
+                            $rp = $f;
715
+                        } # realpath n'est peut etre pas autorise
716
+                        if (!isset($recurs[$rp])) {
717
+                            $recurs[$rp] = true;
718
+                            $beginning = $fichiers;
719
+                            $end = preg_files("$f/", $pattern,
720
+                                $maxfiles - $nbfiles, $recurs);
721
+                            $fichiers = array_merge((array)$beginning, (array)$end);
722
+                            $nbfiles = count($fichiers);
723
+                        }
724
+                    }
725
+                }
726
+            }
727
+        }
728
+        closedir($d);
729
+    }
730
+    sort($fichiers);
731
+
732
+    return $fichiers;
733 733
 }
Please login to merge, or discard this patch.