texinfo-commits
[Top][All Lists]
Advanced

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

[5417] install-info: handle compressed input file names with spaces, etc


From: karl
Subject: [5417] install-info: handle compressed input file names with spaces, etc.
Date: Wed, 19 Feb 2014 18:11:50 +0000

Revision: 5417
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5417
Author:   karl
Date:     2014-02-19 18:11:49 +0000 (Wed, 19 Feb 2014)
Log Message:
-----------
install-info: handle compressed input file names with spaces, etc.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/NEWS
    trunk/install-info/install-info.c
    trunk/install-info/tests/Makefile.am

Added Paths:
-----------
    trunk/install-info/tests/ii-0054-expected-dir-file
    trunk/install-info/tests/ii-0054-input-dir-file
    trunk/install-info/tests/ii-0054-input-info-file.gz
    trunk/install-info/tests/ii-0054-test

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-02-17 00:36:37 UTC (rev 5416)
+++ trunk/ChangeLog     2014-02-19 18:11:49 UTC (rev 5417)
@@ -1,3 +1,21 @@
+2014-02-19  Karl Berry  <address@hidden>
+
+       * install-info/tests/ii-0054-*,
+       * install-info/tests/Makefile.am (TESTS, EXTRA_DIST): new test 54
+       for space in input name.
+
+2014-02-19  Paul Eggert  <address@hidden>
+
+       * install-info/install-info.c (open_possibly_compressed_file):
+       Work even if the file name contains arbitrary shell
+       metacharacters, for example:
+         install-info --info-dir="/d/a b/info" "/d/a b/info/emacs.info.gz"
+       Do this by running the decompressor on standard
+       input, rather than by having the shell open the file.
+       Return either stdin or a pipe.
+       Don't bother with IS_PIPE arg; no longer needed.
+       All callers changed.  Check for freopen failure.
+
 2014-02-16  Karl Berry  <address@hidden>
 
        * doc/texinfo.tex (\ifusebracesinindexes): new conditional for testing.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS  2014-02-17 00:36:37 UTC (rev 5416)
+++ trunk/NEWS  2014-02-19 18:11:49 UTC (rev 5417)
@@ -4,8 +4,7 @@
 
   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
-  2013, 2014
-  Free Software Foundation, Inc.
+  2013, 2014 Free Software Foundation, Inc.
 
   Copying and distribution of this file, with or without modification,
   are permitted in any medium without royalty provided the copyright
@@ -28,7 +27,16 @@
   . @url/@uref output now the same in PDF as in DVI, showing the url
     even if the second argument is given, not just as link target.
     Option \urefurlonlylinktrue gives previous behavior of invisible urls.
-    
+    PDF-only \linkcolor and \urlcolor to specify colors (default black).
+
+* texi2any:
+  . new customization variable INDEX_SPECIAL_CHARS_WARNING to complain
+    when index entries contain a colon.
+  . Docbook output no longer uses <lineannotation> for @r.
+
+* install-info:
+  . handle compressed input file names containing spaces.
+
 5.2 (26 September 2013)
 * Language:
   . new commands @inlinefmtifelse, @inlineifset, @inlineifclear, for

Modified: trunk/install-info/install-info.c
===================================================================
--- trunk/install-info/install-info.c   2014-02-17 00:36:37 UTC (rev 5416)
+++ trunk/install-info/install-info.c   2014-02-19 18:11:49 UTC (rev 5417)
@@ -667,13 +667,16 @@
    If we do open it, return the actual name of the file opened in
    OPENED_FILENAME and the compress program to use to (de)compress it in
    COMPRESSION_PROGRAM.  The compression program is determined by the
+   magic number, not the filename.
    
-   MAGIC number, not the filename.  */
+   Return either stdin reading the file, or a non-stdin pipe reading
+   the output of the compression program.  */
 
+
 FILE *
 open_possibly_compressed_file (char *filename,
     void (*create_callback) (char *),
-    char **opened_filename, char **compression_program, int *is_pipe) 
+    char **opened_filename, char **compression_program) 
 {
   char *local_opened_filename, *local_compression_program;
   int nread;
@@ -686,48 +689,48 @@
     opened_filename = &local_opened_filename;
 
   *opened_filename = filename;
-  f = fopen (*opened_filename, FOPEN_RBIN);
+  f = freopen (*opened_filename, FOPEN_RBIN, stdin);
   if (!f)
     {
       *opened_filename = concat (filename, ".gz", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".xz", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".bz2", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".lz", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
   if (!f)
     {
      free (*opened_filename);
      *opened_filename = concat (filename, ".lzma", "");
-     f = fopen (*opened_filename, FOPEN_RBIN);
+     f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
 #ifdef __MSDOS__
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".igz", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
   if (!f)
     {
       free (*opened_filename);
       *opened_filename = concat (filename, ".inz", "");
-      f = fopen (*opened_filename, FOPEN_RBIN);
+      f = freopen (*opened_filename, FOPEN_RBIN, stdin);
     }
 #endif /* __MSDOS__ */
    if (!f)
@@ -739,7 +742,7 @@
            /* And try opening it again.  */
            free (*opened_filename);
            *opened_filename = filename;
-           f = fopen (*opened_filename, FOPEN_RBIN);
+           f = freopen (*opened_filename, FOPEN_RBIN, stdin);
            if (!f)
              pfatal_with_name (filename);
          }
@@ -819,27 +822,26 @@
   else
     *compression_program = NULL;
 
+  /* Seek back over the magic bytes.  */
+  if (fseek (f, 0, 0) < 0)
+    pfatal_with_name (*opened_filename);
+
   if (*compression_program)
-    { /* It's compressed, so fclose the file and then open a pipe.  */
-      char *command = concat (*compression_program," -cd <", *opened_filename);
-      if (fclose (f) < 0)
-        pfatal_with_name (*opened_filename);
+    { /* It's compressed, so open a pipe.  */
+      char *command = concat (*compression_program, " -d", "");
       f = popen (command, "r");
-      if (f)
-        *is_pipe = 1;
-      else
+      if (! f)
         pfatal_with_name (command);
     }
   else
-    { /* It's a plain file, seek back over the magic bytes.  */
-      if (fseek (f, 0, 0) < 0)
-        pfatal_with_name (*opened_filename);
+    {
 #if O_BINARY
       /* Since this is a text file, and we opened it in binary mode,
          switch back to text mode.  */
       f = freopen (*opened_filename, "r", f);
+      if (! f)
+       pfatal_with_name (*opened_filename);
 #endif
-      *is_pipe = 0;
     }
 
   return f;
@@ -860,7 +862,6 @@
 {
   char *real_name;
   FILE *f;
-  int pipe_p;
   int filled = 0;
   int data_size = 8192;
   char *data = xmalloc (data_size);
@@ -869,7 +870,7 @@
   f = open_possibly_compressed_file (filename, create_callback,
                                      opened_filename ? opened_filename
                                                      : &real_name,
-                                     compression_program, &pipe_p);
+                                     compression_program);
 
   for (;;)
     {
@@ -892,10 +893,8 @@
   /* We need to close the stream, since on some systems the pipe created
      by popen is simulated by a temporary file which only gets removed
      inside pclose.  */
-  if (pipe_p)
+  if (f != stdin)
     pclose (f);
-  else
-    fclose (f);
 
   *sizep = filled;
   return data;
@@ -1906,6 +1905,12 @@
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
+  /* Make sure standard input can be freopened at will.  Otherwise,
+     when stdin starts off closed, bad things could happen if a plain fopen
+     returns stdin before open_possibly_compressed_file freopens it.  */
+  if (! freopen (NULL_DEVICE, "r", stdin))
+    pfatal_with_name (NULL_DEVICE);
+
   munge_old_style_debian_options (argc, argv, &argc, &argv);
 
   while (1)

Modified: trunk/install-info/tests/Makefile.am
===================================================================
--- trunk/install-info/tests/Makefile.am        2014-02-17 00:36:37 UTC (rev 
5416)
+++ trunk/install-info/tests/Makefile.am        2014-02-19 18:11:49 UTC (rev 
5417)
@@ -1,7 +1,7 @@
 # $Id$
 # Makefile.am for texinfo/install-info/tests.
 #
-# Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright 2008, 2009, 2010, 2013, 2014 Free Software Foundation, Inc.
 #
 # This file is free software; as a special exception the author gives
 # unlimited permission to copy and/or distribute it, with or without
@@ -21,7 +21,7 @@
 ii-0036-test ii-0037-test ii-0038-test ii-0039-test ii-0040-test \
 ii-0041-test ii-0042-test ii-0043-test ii-0044-test ii-0045-test \
 ii-0046-test ii-0047-test ii-0048-test ii-0049-test ii-0050-test \
-ii-0051-test ii-0052-test ii-0053-test
+ii-0051-test ii-0052-test ii-0053-test ii-0054-test
 
 noinst_SCRIPTS=$(TESTS)
 
@@ -235,4 +235,8 @@
 ii-0053-input-info-file \
 ii-0053-expected-dir-file \
 ii-0053-test \
+ii-0054-input-dir-file \
+ii-0054-input-info-file \
+ii-0054-expected-dir-file \
+ii-0054-test \
 README

Added: trunk/install-info/tests/ii-0054-expected-dir-file
===================================================================
--- trunk/install-info/tests/ii-0054-expected-dir-file                          
(rev 0)
+++ trunk/install-info/tests/ii-0054-expected-dir-file  2014-02-19 18:11:49 UTC 
(rev 5417)
@@ -0,0 +1,18 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+  topmost node of the Info hierarchy.
+
+
+File: dir,     Node: Top,      This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+  `q' quits;
+  `?' lists all Info commands;
+  `h' starts the Info tutorial;
+  `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu).                   Wildebeest native to Africa.

Added: trunk/install-info/tests/ii-0054-input-dir-file
===================================================================
--- trunk/install-info/tests/ii-0054-input-dir-file                             
(rev 0)
+++ trunk/install-info/tests/ii-0054-input-dir-file     2014-02-19 18:11:49 UTC 
(rev 5417)
@@ -0,0 +1,15 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+  topmost node of the Info hierarchy.
+
+
+File: dir,     Node: Top,      This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+  `q' quits;
+  `?' lists all Info commands;
+  `h' starts the Info tutorial;
+  `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:

Added: trunk/install-info/tests/ii-0054-input-info-file.gz
===================================================================
(Binary files differ)


Property changes on: trunk/install-info/tests/ii-0054-input-info-file.gz
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/install-info/tests/ii-0054-test
===================================================================
--- trunk/install-info/tests/ii-0054-test                               (rev 0)
+++ trunk/install-info/tests/ii-0054-test       2014-02-19 18:11:49 UTC (rev 
5417)
@@ -0,0 +1,39 @@
+#!/bin/sh -x
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+. ./defs || exit 1
+
+outputdirfile=`mktemp ii54-XXXXXXXX`
+cp ${testdir}/ii-0054-input-dir-file $outputdirfile || exit $?
+
+# test compressed input file names with spaces (but avoid having such a
+# name in the repository).
+info_with_space='ii54 input.info.gz'
+cp ${testdir}/ii-0054-input-info-file.gz "$info_with_space"
+${install_info} "$info_with_space" $outputdirfile || exit $?
+
+diff ${testdir}/ii-0054-expected-dir-file $outputdirfile || exit $?
+
+rm -f "$info_with_space" $outputdirfile
+exit $retval
+
+
+#output_dir=`mktemp 'ii 54'-XXXXXXXX`
+#outputdirfile=`mktemp ii53-XXXXXXXX`
+#
+## Test for spaces in target directory name.
+#${install_info} --info-dir="${output_dir}" ${testdir}/ii-0054-input-info-file 
+#test $? = 0 || exit 2
+#
+#diff ${testdir}/ii-0053-expected-dir-file $outputdirfile
+#test $? = 0 || exit 3
+#
+#rm -f $outputdirfile
+#exit 0
+#


Property changes on: trunk/install-info/tests/ii-0054-test
___________________________________________________________________
Added: svn:executable
   + *




reply via email to

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