texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Sat, 13 Apr 2024 09:59:40 -0400 (EDT)

branch: master
commit 47b45b6c87b02452a48e45644d41ed28bbd9fdac
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Apr 13 14:35:20 2024 +0200

    * tp/Texinfo/Common.pm (output_files_open_out),
    tp/Texinfo/Convert/HTML.pm (_do_jslicenses_file): have
    output_files_open_out return the information that a file that was
    already opened is opened agains, which means overwritting.  Add a
    warning in the case that can actually happen, with js licenses file.
    
    * tp/tests/formatting/list-of-tests (js_license_reuse_output_file):
    test with js licences file overwritting an output file.
---
 ChangeLog                                          | 13 +++++-
 tp/Texinfo/Common.pm                               | 24 ++++++----
 tp/Texinfo/Convert/Converter.pm                    |  2 +
 tp/Texinfo/Convert/HTML.pm                         | 13 +++++-
 tp/Texinfo/Convert/IXIN.pm                         |  2 +
 tp/Texinfo/Convert/Info.pm                         |  3 ++
 tp/Texinfo/Convert/LaTeX.pm                        |  2 +
 tp/Texinfo/Convert/Plaintext.pm                    |  2 +
 tp/Texinfo/Convert/Text.pm                         |  2 +
 tp/tests/Makefile.onetst                           |  1 +
 tp/tests/formatting/list-of-tests                  |  3 ++
 .../js_license_reuse_output_file/Ch1.html          | 16 +++++++
 .../js_license_reuse_output_file/index.html        | 54 ++++++++++++++++++++++
 .../js_license_reuse_output_file/js/info.css       |  0
 .../js_license_reuse_output_file/js/info.js        |  0
 .../js_license_reuse_output_file/js/modernizr.js   |  0
 .../js_license_reuse_output_file/split_nocopying.1 |  0
 .../js_license_reuse_output_file/split_nocopying.2 |  1 +
 .../formatting_js_license_reuse_output_file.sh     | 19 ++++++++
 tp/texi2any.pl                                     |  6 +++
 20 files changed, 151 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d9302efb2f..e2e524cee9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,20 @@
+2024-04-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (output_files_open_out),
+       tp/Texinfo/Convert/HTML.pm (_do_jslicenses_file): have
+       output_files_open_out return the information that a file that was
+       already opened is opened agains, which means overwritting.  Add a
+       warning in the case that can actually happen, with js licenses file.
+
+       * tp/tests/formatting/list-of-tests (js_license_reuse_output_file):
+       test with js licences file overwritting an output file.
+
 2024-04-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (output_files_initialize)
        (output_files_open_out, output_files_opened_files), tp/texi2any.pl
        (_exit, %opened_files, handle_errors): use a hash instead of an array
-       for opened files, to avoid unlinling twice files opened (and closed)
+       for opened files, to avoid unlinking twice files opened (and closed)
        twice.
 
 2024-04-13  Patrice Dumas  <pertusus@free.fr>
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 6e23c96727..153064ce64 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -657,6 +657,7 @@ sub output_files_disable_output_encoding($$)
 # Returns
 #  - the opened filehandle, or undef if opening failed,
 #  - the $! error message or undef if opening succeeded.
+#  - 1 if the $FILE_PATH was already opened, which means overwritting.
 sub output_files_open_out($$$;$$)
 {
   my $self = shift;
@@ -686,10 +687,22 @@ sub output_files_open_out($$$;$$)
     }
     return \*STDOUT, undef;
   }
+
+  # Check that this file has not already been registered
+  # as opened_file.  If yes, it will be overwritten if open succeeds.
+  # It is not possible to use the file name twice in converters
+  # for regular output as files are only closed when all the output
+  # units have been written.  It could be possible in HTML with js
+  # scripts licence file set by the user to the same name as an output
+  # file.
+  my $overwritten_file = 0;
+  if (exists($self->{'opened_files'}->{$file_path})) {
+    $overwritten_file = 1;
+  }
   my $filehandle = do { local *FH };
   if (!open ($filehandle, '>', $file_path)) {
     my $error_message = $!;
-    return undef, $error_message;
+    return undef, $error_message, $overwritten_file;
   }
   # If $use_binmode is true, we run binmode to turn off outputting LF as CR LF
   # under MS-Windows, so that Info tag tables will have correct offsets.  This
@@ -702,18 +715,11 @@ sub output_files_open_out($$$;$$)
     if ($self->{'unclosed_files'}->{$file_path}) {
       warn "BUG: already open: $file_path\n";
     } else {
-      # FIXME check that this file has not already been registered
-      # as opened_file?  If not, it probably has been overwritten.
-      # It is not possible to use the file name twice in converters
-      # for regular output as files are only closed when all the output
-      # units have been written.  It could be possible in HTML with js
-      # scripts licence files set to the same name as an output unit, which
-      # is not possible in the default case.
       $self->{'opened_files'}->{$file_path} = 1;
     }
     $self->{'unclosed_files'}->{$file_path} = $filehandle;
   }
-  return $filehandle, undef;
+  return $filehandle, undef, $overwritten_file;
 }
 
 # see the description of $SELF in comment above output_files_open_out.
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 0b4bc05e4c..25b263a4b7 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -392,6 +392,8 @@ sub output_tree($$)
     ($encoded_output_file, $path_encoding)
       = $self->encoded_output_file_name($output_file);
     my $error_message;
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                               $self->output_files_information(), $self,
                               $encoded_output_file);
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 9d0e4daaf2..f33425eb23 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -11625,7 +11625,7 @@ sub _do_jslicenses_file {
 
   if (File::Spec->file_name_is_absolute($path) or $path =~ /^[A-Za-z]*:/) {
     $self->converter_document_warn(sprintf(
-__("cannot use absolute path or URL `%s' for JS_WEBLABELS_FILE when generating 
web labels file"), $path));
+ __("cannot use absolute path or URL `%s' for JS_WEBLABELS_FILE when 
generating web labels file"), $path));
     return;
   }
   my $license_file;
@@ -11637,10 +11637,15 @@ __("cannot use absolute path or URL `%s' for 
JS_WEBLABELS_FILE when generating w
   # sequence of bytes
   my ($licence_file_path, $path_encoding)
      = $self->encoded_output_file_name($license_file);
-  my ($fh, $error_message_licence_file)
+  my ($fh, $error_message_licence_file, $overwritten_file)
          = Texinfo::Common::output_files_open_out(
                          $self->output_files_information(), $self,
                          $licence_file_path);
+  if ($overwritten_file) {
+    $self->converter_document_warn(
+     sprintf(__("overwritting output file with js licences: %s"),
+             $license_file));
+  }
   if (defined($fh)) {
     print $fh $a;
     Texinfo::Common::output_files_register_closed(
@@ -12576,6 +12581,8 @@ sub _html_convert_output($$$$$$$$)
         my $file_output_unit = $files{$output_unit_filename}->{'first_unit'};
         my ($encoded_out_filepath, $path_encoding)
           = $self->encoded_output_file_name($out_filepath);
+        # the third return information, set if the file has already been used
+        # in this files_information is not checked as this cannot happen.
         my ($file_fh, $error_message)
                 = Texinfo::Common::output_files_open_out(
                          $self->output_files_information(), $self,
@@ -12776,6 +12783,8 @@ sub _node_redirections($$$$)
         }
         my ($encoded_out_filepath, $path_encoding)
           = $self->encoded_output_file_name($out_filepath);
+        # the third return information, set if the file has already been used
+        # in this files_information is not checked as this cannot happen.
         my ($file_fh, $error_message)
                = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index 0c8a2b5836..749e7d4de1 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -345,6 +345,8 @@ sub output_ixin($$)
     ($encoded_output_file, $path_encoding)
       = $self->encoded_output_file_name($output_file);
     my $error_message;
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
                              $encoded_output_file);
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index a2e5039073..c8582b94a9 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -379,6 +379,9 @@ sub _open_info_file($$)
 
   my ($encoded_filename, $path_encoding)
       = $self->encoded_output_file_name($filename);
+
+  # the third return information, set if the file has already been used
+  # in this files_information is not checked as this cannot happen.
   my ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                                $self->output_files_information(), $self,
                                $encoded_filename, 'use_binmode');
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index cfe6b55596..907d760a8f 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -1094,6 +1094,8 @@ sub output($$)
     ($encoded_output_file, $path_encoding)
       = $self->encoded_output_file_name($output_file);
     my $error_message;
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
                              $encoded_output_file);
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index c4f1fe0cef..cf9a7ec309 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -748,6 +748,8 @@ sub output($$)
       ($encoded_outfile_name, $path_encoding)
         = $self->encoded_output_file_name($outfile_name);
       my $error_message;
+      # the third return information, set if the file has already been used
+      # in this files_information is not checked as this cannot happen.
       ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                     $self->output_files_information(), $self,
                     $encoded_outfile_name);
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index c9f1038f73..250d942398 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -968,6 +968,8 @@ sub output($$)
     ($encoded_outfile, $outfile_encoding)
       = Texinfo::Convert::Utils::encoded_output_file_name($self, $outfile);
     my $error_message;
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     ($fh, $error_message) = Texinfo::Common::output_files_open_out(
                              $self->{'output_files'}, $self,
                              $encoded_outfile);
diff --git a/tp/tests/Makefile.onetst b/tp/tests/Makefile.onetst
index dbfe4b01f0..51729ada8b 100644
--- a/tp/tests/Makefile.onetst
+++ b/tp/tests/Makefile.onetst
@@ -37,6 +37,7 @@ type_base_one_test_files_generated_list =  \
     test_scripts/formatting_formatting_customizations_input_raw_text.sh \
     test_scripts/formatting_index_entries_relate_to_item.sh \
     test_scripts/formatting_info_extension_warning.sh \
+    test_scripts/formatting_js_license_reuse_output_file.sh \
     test_scripts/encoded_non_ascii_command_line.sh \
     test_scripts/encoded_non_ascii_test_epub.sh \
     test_scripts/encoded_non_ascii_test_rawtext.sh \
diff --git a/tp/tests/formatting/list-of-tests 
b/tp/tests/formatting/list-of-tests
index fc5dbde4ce..42342b0d53 100644
--- a/tp/tests/formatting/list-of-tests
+++ b/tp/tests/formatting/list-of-tests
@@ -37,3 +37,6 @@ index_entries_relate_to_item 
index_entries_relate_to_item.texi --html --no-split
 
 info_extension_warning foo.info
 
+# test JS_WEBLABELS_FILE set to a file already output as part of the manual
+# formatting.
+js_license_reuse_output_file split_nocopying.texi --html -c 
JS_WEBLABELS_FILE=Ch1.html -c INFO_JS_DIR=js
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/Ch1.html 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/Ch1.html
new file mode 100644
index 0000000000..ba8195f345
--- /dev/null
+++ b/tp/tests/formatting/res_parser/js_license_reuse_output_file/Ch1.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html><head><title>jslicense labels</title></head>
+<body>
+<table id="jslicense-labels1">
+<tr>
+<td><a href="js/info.js">js/info.js</a></td>
+<td><a href="http://www.gnu.org/licenses/gpl-3.0.html";>GNU General Public 
License 3.0 or later</a></td>
+<td><a href="js/info.js">js/info.js</a></td>
+</tr>
+<tr>
+<td><a href="js/modernizr.js">js/modernizr.js</a></td>
+<td><a href="http://www.jclark.com/xml/copying.txt";>Expat</a></td>
+<td><a href="js/modernizr.js">js/modernizr.js</a></td>
+</tr>
+</table>
+</body></html>
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/index.html 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/index.html
new file mode 100644
index 0000000000..c4be3e4281
--- /dev/null
+++ b/tp/tests/formatting/res_parser/js_license_reuse_output_file/index.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Top (Test file used to test split Info without @copying)</title>
+
+<meta name="description" content="Top (Test file used to test split Info 
without @copying)">
+<meta name="keywords" content="Top (Test file used to test split Info without 
@copying)">
+<meta name="resource-type" content="document">
+<meta name="distribution" content="global">
+<meta name="Generator" content="texi2any">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+
+<link href="#Top" rel="start" title="Top">
+<link href="Ch1.html" rel="next" title="Ch1">
+<style type="text/css">
+<!--
+a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
+span:hover a.copiable-link {visibility: visible}
+-->
+</style>
+
+<link rel="stylesheet" type="text/css" href="js/info.css">
+<script src="js/modernizr.js" type="text/javascript"></script>
+<script src="js/info.js" type="text/javascript"></script>
+</head>
+
+<body lang="en">
+<div class="top-level-extent" id="Top">
+<div class="nav-panel">
+<p>
+Next: <a href="Ch1.html" accesskey="n" rel="next">Ch1</a> &nbsp; </p>
+</div>
+<hr>
+<h1 class="top" 
id="Test-file-used-to-test-split-Info-without-_0040copying"><span>Test file 
used to test split Info without @copying<a class="copiable-link" 
href="#Test-file-used-to-test-split-Info-without-_0040copying"> 
&para;</a></span></h1>
+
+<p>This is the top node.
+</p>
+
+<ul class="mini-toc">
+<li><a href="Ch1.html" accesskey="1">Ch1</a></li>
+</ul>
+</div>
+<hr>
+<div class="nav-panel">
+<p>
+Next: <a href="Ch1.html" accesskey="n" rel="next">Ch1</a> &nbsp; </p>
+</div>
+
+
+<a href="Ch1.html" rel="jslicense"><small>JavaScript license 
information</small></a>
+</body>
+</html>
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/info.css 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/info.css
new file mode 100644
index 0000000000..e69de29bb2
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/info.js 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/info.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/modernizr.js 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/js/modernizr.js
new file mode 100644
index 0000000000..e69de29bb2
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/split_nocopying.1 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/split_nocopying.1
new file mode 100644
index 0000000000..e69de29bb2
diff --git 
a/tp/tests/formatting/res_parser/js_license_reuse_output_file/split_nocopying.2 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/split_nocopying.2
new file mode 100644
index 0000000000..d1d81b38d8
--- /dev/null
+++ 
b/tp/tests/formatting/res_parser/js_license_reuse_output_file/split_nocopying.2
@@ -0,0 +1 @@
+texi2any: warning: overwritting output file with js licences: 
formatting/out_parser/js_license_reuse_output_file/Ch1.html
diff --git a/tp/tests/test_scripts/formatting_js_license_reuse_output_file.sh 
b/tp/tests/test_scripts/formatting_js_license_reuse_output_file.sh
new file mode 100755
index 0000000000..6200a1070e
--- /dev/null
+++ b/tp/tests/test_scripts/formatting_js_license_reuse_output_file.sh
@@ -0,0 +1,19 @@
+#! /bin/sh
+# This file generated by maintain/regenerate_cmd_tests.sh
+
+if test z"$srcdir" = "z"; then
+  srcdir=.
+fi
+
+one_test_logs_dir=test_log
+
+
+dir=formatting
+name='js_license_reuse_output_file'
+mkdir -p $dir
+
+"$srcdir"/run_parser_all.sh -dir $dir $name
+exit_status=$?
+cat $dir/$one_test_logs_dir/$name.log
+exit $exit_status
+
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 04132e494b..ad61f1f044 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1576,6 +1576,8 @@ while(@input_files) {
     my $macro_expand_file_name = 
_decode_input($encoded_macro_expand_file_name);
     my $macro_expand_files_information
           = Texinfo::Common::output_files_initialize();
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     my ($macro_expand_fh, $error_message)
           = Texinfo::Common::output_files_open_out(
                           $macro_expand_files_information, $document,
@@ -1779,6 +1781,8 @@ while(@input_files) {
         = _decode_input($encoded_internal_links_file_name);
     my $internal_links_files_information
          = Texinfo::Common::output_files_initialize();
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     my ($internal_links_fh, $error_message)
             = Texinfo::Common::output_files_open_out(
                               $internal_links_files_information, $converter,
@@ -1858,6 +1862,8 @@ while(@input_files) {
                                              $sort_element_count_file_name);
     my $sort_elem_files_information
           = Texinfo::Common::output_files_initialize();
+    # the third return information, set if the file has already been used
+    # in this files_information is not checked as this cannot happen.
     my ($sort_element_count_fh, $error_message)
                 = Texinfo::Common::output_files_open_out(
                        $sort_elem_files_information, $converter_element_count,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]