Completed
Push — master ( 4a1dc4...073957 )
by cam
01:19
created
ecrire/inc/flock.php 1 patch
Indentation   +407 added lines, -407 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$,', $_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$,', $_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'] = [];
@@ -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] = [$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] = [$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 = []) {
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,25 +330,25 @@  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 (
338
-		$force
339
-		or !file_exists($fichier)
340
-		or md5_file($fichier) != md5_file($fichier_tmp)
341
-	) {
342
-		if ($use_copy) {
343
-			@copy($fichier_tmp, $fichier);
344
-		}
345
-		else {
346
-			@rename($fichier_tmp, $fichier);
347
-		}
348
-		// eviter que PHP ne reserve le vieux timestamp
349
-		clearstatcache(true, $fichier);
350
-	}
351
-	return true;
333
+    $fichier_tmp = $fichier . '.last';
334
+    if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335
+        return false;
336
+    }
337
+    if (
338
+        $force
339
+        or !file_exists($fichier)
340
+        or md5_file($fichier) != md5_file($fichier_tmp)
341
+    ) {
342
+        if ($use_copy) {
343
+            @copy($fichier_tmp, $fichier);
344
+        }
345
+        else {
346
+            @rename($fichier_tmp, $fichier);
347
+        }
348
+        // eviter que PHP ne reserve le vieux timestamp
349
+        clearstatcache(true, $fichier);
350
+    }
351
+    return true;
352 352
 }
353 353
 
354 354
 
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
  *     true si l'opération a réussie, false sinon.
370 370
  */
371 371
 function lire_fichier_securise($fichier, &$contenu, $options = []) {
372
-	if ($res = lire_fichier($fichier, $contenu, $options)) {
373
-		$contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
-	}
372
+    if ($res = lire_fichier($fichier, $contenu, $options)) {
373
+        $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
+    }
375 375
 
376
-	return $res;
376
+    return $res;
377 377
 }
378 378
 
379 379
 /**
@@ -388,25 +388,25 @@  discard block
 block discarded – undo
388 388
  *     Chemin du fichier
389 389
  **/
390 390
 function raler_fichier($fichier) {
391
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
392
-		spip_initialisation_suite();
393
-	}
394
-	include_spip('inc/minipres');
395
-	$dir = dirname($fichier);
396
-	http_response_code(401);
397
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
398
-		. _T('texte_inc_meta_1', ['fichier' => $fichier])
399
-		. " <a href='"
400
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
401
-		. "'>"
402
-		. _T('texte_inc_meta_2')
403
-		. '</a> '
404
-		. _T(
405
-			'texte_inc_meta_3',
406
-			['repertoire' => joli_repertoire($dir)]
407
-		)
408
-		. "</h4>\n");
409
-	exit;
391
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
392
+        spip_initialisation_suite();
393
+    }
394
+    include_spip('inc/minipres');
395
+    $dir = dirname($fichier);
396
+    http_response_code(401);
397
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
398
+        . _T('texte_inc_meta_1', ['fichier' => $fichier])
399
+        . " <a href='"
400
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
401
+        . "'>"
402
+        . _T('texte_inc_meta_2')
403
+        . '</a> '
404
+        . _T(
405
+            'texte_inc_meta_3',
406
+            ['repertoire' => joli_repertoire($dir)]
407
+        )
408
+        . "</h4>\n");
409
+    exit;
410 410
 }
411 411
 
412 412
 
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
  *     - true si récent, false sinon
422 422
  */
423 423
 function jeune_fichier($fichier, $n) {
424
-	if (!file_exists($fichier)) {
425
-		return false;
426
-	}
427
-	if (!$c = @filemtime($fichier)) {
428
-		return false;
429
-	}
430
-
431
-	return (time() - $n <= $c);
424
+    if (!file_exists($fichier)) {
425
+        return false;
426
+    }
427
+    if (!$c = @filemtime($fichier)) {
428
+        return false;
429
+    }
430
+
431
+    return (time() - $n <= $c);
432 432
 }
433 433
 
434 434
 /**
@@ -443,22 +443,22 @@  discard block
 block discarded – undo
443 443
  *     - false si on n'arrive pas poser le verrou ou si la suppression échoue
444 444
  */
445 445
 function supprimer_fichier($fichier, $lock = true) {
446
-	if (!@file_exists($fichier)) {
447
-		return true;
448
-	}
449
-
450
-	if ($lock) {
451
-		// verrouiller le fichier destination
452
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
453
-			return false;
454
-		}
455
-
456
-		// liberer le verrou
457
-		spip_fclose_unlock($fp);
458
-	}
459
-
460
-	// supprimer
461
-	return @unlink($fichier);
446
+    if (!@file_exists($fichier)) {
447
+        return true;
448
+    }
449
+
450
+    if ($lock) {
451
+        // verrouiller le fichier destination
452
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
453
+            return false;
454
+        }
455
+
456
+        // liberer le verrou
457
+        spip_fclose_unlock($fp);
458
+    }
459
+
460
+    // supprimer
461
+    return @unlink($fichier);
462 462
 }
463 463
 
464 464
 /**
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
  *     Chemin du fichier
469 469
  */
470 470
 function spip_unlink($f) {
471
-	if (!is_dir($f)) {
472
-		supprimer_fichier($f, false);
473
-	} else {
474
-		@unlink("$f/.ok");
475
-		@rmdir($f);
476
-	}
471
+    if (!is_dir($f)) {
472
+        supprimer_fichier($f, false);
473
+    } else {
474
+        @unlink("$f/.ok");
475
+        @rmdir($f);
476
+    }
477 477
 }
478 478
 
479 479
 /**
@@ -487,26 +487,26 @@  discard block
 block discarded – undo
487 487
  *   The absolute path of the PHP file to invalidate.
488 488
  */
489 489
 function spip_clear_opcode_cache($filepath) {
490
-	clearstatcache(true, $filepath);
491
-
492
-	// Zend OPcache
493
-	if (function_exists('opcache_invalidate')) {
494
-		$invalidate = @opcache_invalidate($filepath, true);
495
-		// si l'invalidation a echoue lever un flag
496
-		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
497
-			define('_spip_attend_invalidation_opcode_cache', true);
498
-		}
499
-	} elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
500
-		// n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
501
-		define('_spip_attend_invalidation_opcode_cache', true);
502
-	}
503
-	// APC.
504
-	if (function_exists('apc_delete_file')) {
505
-		// apc_delete_file() throws a PHP warning in case the specified file was
506
-		// not compiled yet.
507
-		// @see http://php.net/apc-delete-file
508
-		@apc_delete_file($filepath);
509
-	}
490
+    clearstatcache(true, $filepath);
491
+
492
+    // Zend OPcache
493
+    if (function_exists('opcache_invalidate')) {
494
+        $invalidate = @opcache_invalidate($filepath, true);
495
+        // si l'invalidation a echoue lever un flag
496
+        if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
497
+            define('_spip_attend_invalidation_opcode_cache', true);
498
+        }
499
+    } elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
500
+        // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
501
+        define('_spip_attend_invalidation_opcode_cache', true);
502
+    }
503
+    // APC.
504
+    if (function_exists('apc_delete_file')) {
505
+        // apc_delete_file() throws a PHP warning in case the specified file was
506
+        // not compiled yet.
507
+        // @see http://php.net/apc-delete-file
508
+        @apc_delete_file($filepath);
509
+    }
510 510
 }
511 511
 
512 512
 /**
@@ -529,25 +529,25 @@  discard block
 block discarded – undo
529 529
  *
530 530
  */
531 531
 function spip_attend_invalidation_opcode_cache($timestamp = null) {
532
-	if (
533
-		function_exists('opcache_get_configuration')
534
-		and @ini_get('opcache.enable')
535
-		and @ini_get('opcache.validate_timestamps')
536
-		and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
537
-		and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
538
-	) {
539
-		$wait = $duree + 1;
540
-		if ($timestamp) {
541
-			$wait -= (time() - $timestamp);
542
-			if ($wait < 0) {
543
-				$wait = 0;
544
-			}
545
-		}
546
-		spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
547
-		if ($wait) {
548
-			sleep($duree + 1);
549
-		}
550
-	}
532
+    if (
533
+        function_exists('opcache_get_configuration')
534
+        and @ini_get('opcache.enable')
535
+        and @ini_get('opcache.validate_timestamps')
536
+        and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
537
+        and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
538
+    ) {
539
+        $wait = $duree + 1;
540
+        if ($timestamp) {
541
+            $wait -= (time() - $timestamp);
542
+            if ($wait < 0) {
543
+                $wait = 0;
544
+            }
545
+        }
546
+        spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
547
+        if ($wait) {
548
+            sleep($duree + 1);
549
+        }
550
+    }
551 551
 }
552 552
 
553 553
 
@@ -560,26 +560,26 @@  discard block
 block discarded – undo
560 560
  * @return bool Suppression reussie.
561 561
  */
562 562
 function supprimer_repertoire($dir) {
563
-	if (!file_exists($dir)) {
564
-		return true;
565
-	}
566
-	if (!is_dir($dir) || is_link($dir)) {
567
-		return @unlink($dir);
568
-	}
569
-
570
-	foreach (scandir($dir) as $item) {
571
-		if ($item == '.' || $item == '..') {
572
-			continue;
573
-		}
574
-		if (!supprimer_repertoire($dir . '/' . $item)) {
575
-			@chmod($dir . '/' . $item, 0777);
576
-			if (!supprimer_repertoire($dir . '/' . $item)) {
577
-				return false;
578
-			}
579
-		};
580
-	}
581
-
582
-	return @rmdir($dir);
563
+    if (!file_exists($dir)) {
564
+        return true;
565
+    }
566
+    if (!is_dir($dir) || is_link($dir)) {
567
+        return @unlink($dir);
568
+    }
569
+
570
+    foreach (scandir($dir) as $item) {
571
+        if ($item == '.' || $item == '..') {
572
+            continue;
573
+        }
574
+        if (!supprimer_repertoire($dir . '/' . $item)) {
575
+            @chmod($dir . '/' . $item, 0777);
576
+            if (!supprimer_repertoire($dir . '/' . $item)) {
577
+                return false;
578
+            }
579
+        };
580
+    }
581
+
582
+    return @rmdir($dir);
583 583
 }
584 584
 
585 585
 
@@ -608,57 +608,57 @@  discard block
 block discarded – undo
608 608
  *     Chemin du répertoire créé.
609 609
  **/
610 610
 function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
611
-	static $dirs = [];
612
-
613
-	$base = str_replace('//', '/', $base);
614
-
615
-	# suppr le dernier caractere si c'est un /
616
-	$base = rtrim($base, '/');
617
-
618
-	if (!strlen($subdir)) {
619
-		$n = strrpos($base, '/');
620
-		if ($n === false) {
621
-			return $nobase ? '' : ($base . '/');
622
-		}
623
-		$subdir = substr($base, $n + 1);
624
-		$base = substr($base, 0, $n + 1);
625
-	} else {
626
-		$base .= '/';
627
-		$subdir = str_replace('/', '', $subdir);
628
-	}
629
-
630
-	$baseaff = $nobase ? '' : $base;
631
-	if (isset($dirs[$base . $subdir])) {
632
-		return $baseaff . $dirs[$base . $subdir];
633
-	}
634
-
635
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
636
-
637
-	if (file_exists("$path/.ok")) {
638
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
639
-	}
640
-
641
-	@mkdir($path, _SPIP_CHMOD);
642
-	@chmod($path, _SPIP_CHMOD);
643
-
644
-	if (is_dir($path) && is_writable($path)) {
645
-		@touch("$path/.ok");
646
-		spip_log("creation $base$subdir/");
647
-
648
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
649
-	}
650
-
651
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
652
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
653
-	spip_log("echec creation $base${subdir}");
654
-	if ($tantpis) {
655
-		return '';
656
-	}
657
-	if (!_DIR_RESTREINT) {
658
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
659
-	}
660
-	$base .= $subdir;
661
-	raler_fichier($base . '/.ok');
611
+    static $dirs = [];
612
+
613
+    $base = str_replace('//', '/', $base);
614
+
615
+    # suppr le dernier caractere si c'est un /
616
+    $base = rtrim($base, '/');
617
+
618
+    if (!strlen($subdir)) {
619
+        $n = strrpos($base, '/');
620
+        if ($n === false) {
621
+            return $nobase ? '' : ($base . '/');
622
+        }
623
+        $subdir = substr($base, $n + 1);
624
+        $base = substr($base, 0, $n + 1);
625
+    } else {
626
+        $base .= '/';
627
+        $subdir = str_replace('/', '', $subdir);
628
+    }
629
+
630
+    $baseaff = $nobase ? '' : $base;
631
+    if (isset($dirs[$base . $subdir])) {
632
+        return $baseaff . $dirs[$base . $subdir];
633
+    }
634
+
635
+    $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
636
+
637
+    if (file_exists("$path/.ok")) {
638
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
639
+    }
640
+
641
+    @mkdir($path, _SPIP_CHMOD);
642
+    @chmod($path, _SPIP_CHMOD);
643
+
644
+    if (is_dir($path) && is_writable($path)) {
645
+        @touch("$path/.ok");
646
+        spip_log("creation $base$subdir/");
647
+
648
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
649
+    }
650
+
651
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
652
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
653
+    spip_log("echec creation $base${subdir}");
654
+    if ($tantpis) {
655
+        return '';
656
+    }
657
+    if (!_DIR_RESTREINT) {
658
+        $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
659
+    }
660
+    $base .= $subdir;
661
+    raler_fichier($base . '/.ok');
662 662
 }
663 663
 
664 664
 
@@ -691,56 +691,56 @@  discard block
 block discarded – undo
691 691
  *     Chemins des fichiers trouvés.
692 692
  **/
693 693
 function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) {
694
-	$nbfiles = 0;
695
-	if ($pattern == -1) {
696
-		$pattern = "";
697
-	}
698
-	$fichiers = [];
699
-	// revenir au repertoire racine si on a recu dossier/truc
700
-	// pour regarder dossier/truc/ ne pas oublier le / final
701
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
702
-	if ($dir == '') {
703
-		$dir = '.';
704
-	}
705
-
706
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
707
-		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
708
-			if (
709
-				$f[0] != '.' # ignorer . .. .svn etc
710
-				and $f != 'CVS'
711
-				and $f != 'remove.txt'
712
-				and is_readable($f = "$dir/$f")
713
-			) {
714
-				if (is_file($f)) {
715
-					if (!$pattern or preg_match(";$pattern;iS", $f)) {
716
-						$fichiers[] = $f;
717
-						$nbfiles++;
718
-					}
719
-				} else {
720
-					if (is_dir($f) and is_array($recurs)) {
721
-						$rp = @realpath($f);
722
-						if (!is_string($rp) or !strlen($rp)) {
723
-							$rp = $f;
724
-						} # realpath n'est peut etre pas autorise
725
-						if (!isset($recurs[$rp])) {
726
-							$recurs[$rp] = true;
727
-							$beginning = $fichiers;
728
-							$end = preg_files(
729
-								"$f/",
730
-								$pattern,
731
-								$maxfiles - $nbfiles,
732
-								$recurs
733
-							);
734
-							$fichiers = array_merge((array)$beginning, (array)$end);
735
-							$nbfiles = count($fichiers);
736
-						}
737
-					}
738
-				}
739
-			}
740
-		}
741
-		closedir($d);
742
-	}
743
-	sort($fichiers);
744
-
745
-	return $fichiers;
694
+    $nbfiles = 0;
695
+    if ($pattern == -1) {
696
+        $pattern = "";
697
+    }
698
+    $fichiers = [];
699
+    // revenir au repertoire racine si on a recu dossier/truc
700
+    // pour regarder dossier/truc/ ne pas oublier le / final
701
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
702
+    if ($dir == '') {
703
+        $dir = '.';
704
+    }
705
+
706
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
707
+        while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
708
+            if (
709
+                $f[0] != '.' # ignorer . .. .svn etc
710
+                and $f != 'CVS'
711
+                and $f != 'remove.txt'
712
+                and is_readable($f = "$dir/$f")
713
+            ) {
714
+                if (is_file($f)) {
715
+                    if (!$pattern or preg_match(";$pattern;iS", $f)) {
716
+                        $fichiers[] = $f;
717
+                        $nbfiles++;
718
+                    }
719
+                } else {
720
+                    if (is_dir($f) and is_array($recurs)) {
721
+                        $rp = @realpath($f);
722
+                        if (!is_string($rp) or !strlen($rp)) {
723
+                            $rp = $f;
724
+                        } # realpath n'est peut etre pas autorise
725
+                        if (!isset($recurs[$rp])) {
726
+                            $recurs[$rp] = true;
727
+                            $beginning = $fichiers;
728
+                            $end = preg_files(
729
+                                "$f/",
730
+                                $pattern,
731
+                                $maxfiles - $nbfiles,
732
+                                $recurs
733
+                            );
734
+                            $fichiers = array_merge((array)$beginning, (array)$end);
735
+                            $nbfiles = count($fichiers);
736
+                        }
737
+                    }
738
+                }
739
+            }
740
+        }
741
+        closedir($d);
742
+    }
743
+    sort($fichiers);
744
+
745
+    return $fichiers;
746 746
 }
Please login to merge, or discard this patch.