Skip to content

Commit 0ae92dd

Browse files
authored
Create separated files for directory file-entities (#218)
1 parent 1768961 commit 0ae92dd

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

scripts/file-entities.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
This script creates various "file entities", that is, DTD entities that
2121
point to files and file listings, named and composed of:
2222
23-
- dir.dir.file : pulls in a dir/dir/file.xml
24-
- dir.dif.entities.dir : pulls in all files of dir/dir/dir/*.xml
23+
- dir.dir.file : pulls in a dir/dir/file.xml
24+
- dir.dif.entities.dir : pulls in XML files from dir/dir/dir/*.xml
2525
2626
In the original file-entities.php.in, the files are created at:
2727
@@ -31,7 +31,20 @@
3131
In new idempotent mode, files are created at:
3232
3333
- doc-base/temp/file-entites.ent
34-
- doc-base/temp/file-entites.dir.dir.ent
34+
- doc-base/temp/file-entites/dir.dir.ent
35+
36+
The file entity for directories (file listings) are keep as individual
37+
files instead to avoid these libxml errors, in some OS/versions:
38+
39+
- Detected an entity reference loop [1]
40+
- Maximum entity amplification factor exceeded [2]
41+
42+
See LIBXML_LIMITS_HACK below. This workaround creates about a thousand
43+
files per running, that slowsdows even more the manual building on HDD
44+
systems.
45+
46+
[1] https://github.com/php/doc-base/pull/183
47+
[2] https://github.com/php/doc-en/pull/4330
3548
3649
*/
3750

@@ -43,6 +56,8 @@
4356
set_time_limit( 0 );
4457
ob_implicit_flush();
4558

59+
const LIBXML_LIMITS_HACK = true;
60+
4661
// Usage
4762

4863
$root = realpain( __DIR__ . "/../.." );
@@ -256,15 +271,20 @@ function list_entities_recurse( string $root , array $dirs )
256271
$text = implode( "\n" , $list );
257272

258273
if ( $text != "" )
259-
pushEntity( $name , text: $text );
260-
261-
// Old style, pre LIBXML_PARSEHUGE, "directory" entity as external file
262-
//
263-
// $path = __DIR__ . "/../temp/file-entities." . implode( '.' , $dirs ) . ".ent";
264-
// file_put_contents( $path , $text );
265-
// $path = realpain( $path );
266-
// pushEntity( $name , path: $path );
267-
//
274+
{
275+
if ( LIBXML_LIMITS_HACK )
276+
{
277+
static $entityDir = "";
278+
if ( $entityDir == "" )
279+
$entityDir = realpain( __DIR__ . "/../temp/file-entities" , mkdir: true );
280+
281+
$path = $entityDir . "/" . implode( '.' , $dirs ) . ".ent";
282+
file_put_contents( $path , $text );
283+
pushEntity( $name , path: $path );
284+
}
285+
else
286+
pushEntity( $name , text: $text );
287+
}
268288

269289
foreach( $subdirs as $subdir )
270290
{

0 commit comments

Comments
 (0)