bug-texinfo
[Top][All Lists]
Advanced

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

[PATCH] install-info: fix delete dir file section code


From: John Wheeler
Subject: [PATCH] install-info: fix delete dir file section code
Date: Fri, 24 Mar 2023 12:32:45 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

Gavin,

I offer the following for your consideration.

Thank you,
John Wheeler

====
Bug report: Off-by-one flaw in deleting empty dir section

Current troublesome behavior: install-info adds a blank line
before the final dir file section each time that section is
removed and re-installed.  This is troublesome when a build
test process repeatedly removes and re-inserts a dir section.

Discussion: It is easy to assume that installing and deleting a
section in a dir file should be inverse operations.  That is to
say: deleting a section should exactly undo the effects of
installing that section. It is also easy to assume that the effect
of the delete operation should be consistent independent of the
location of the section being deleted.  For install-info both of
these assumptions are false.

Affected versions: At a minimum all install-info versions since
2008-01-01 when commit b9e0c3d71835b959c0cb6307fced71b692e95947
introduced file 'install-info/tests/ii-0047-expected-dir-file'
which verifies the current behavior.

==== minimal working example ====
A minimal working example that demonstrates the problem follows:

In an empty directory create two files: cow and gnu, as follows.

file: cow
----- cut line -----
INFO-DIR-SECTION Livestock
START-INFO-DIR-ENTRY
* Cow: (cow).                    A farm animal.
END-INFO-DIR-ENTRY

File: cow,  Node: Top,  Next: Top,  Up: (dir)

Cow
***

The cow ...
----- cut line -----

file: gnu
----- cut line -----
INFO-DIR-SECTION Animals
START-INFO-DIR-ENTRY
* Gnu: (gnu).                    Wildebeest native to Africa.
END-INFO-DIR-ENTRY

File: gnu,  Node: Top,  Next: Top,  Up: (dir)

Gnu
***

The wildebeest ...
----- cut line -----

Create an initial dir file with the command:

install-info --info-dir=. --info-file=./cow; \
install-info --info-dir=. --info-file=./gnu; \
cat dir

Repeatedly execute the following command line to observe that
deleting and installing an internal section works as expected:

install-info --remove --info-dir=. --info-file=./gnu; \
install-info --info-dir=. --info-file=./gnu; \
cat dir

Repeatedly execute the following command line to observe that
deleting and reinstalling the terminal section (the section
immediately before the end-of-file) adds a newline before the
section on each repetition:

install-info --remove --info-dir=. --info-file=./cow; \
install-info --info-dir=. --info-file=./cow; \
cat dir

Remove the Animals section by executing:

install-info --remove --info-dir=. --info-file=./gnu

And repeatedly execute:

install-info --remove --info-dir=. --info-file=./cow; \
install-info --info-dir=. --info-file=./cow; \
cat dir

to show that the newline is again added on each repetition.

==== end of minimal working example ====

I offer the following patch to correct this behavior:

====== patch =====
diff --git a/ChangeLog b/ChangeLog
index 92bc4d6325..9435b0213a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-03-24  John Wheeler  <wheelerwjx9@runbox.com>
+
+       * install-info/install-info.c: Make deleting an empty dir file an
+       inverse operation to installing a dir file section.  Current
+       behavior introduces a blank line before each inserted section that
+       deleting it does not remove.
+
 2023-03-21  Patrice Dumas  <pertusus@free.fr>

        Index commands do not end paragraphs in texi2any
diff --git a/install-info/install-info.c b/install-info/install-info.c
index 0899f8c683..5dcbe2fb50 100644
--- a/install-info/install-info.c
+++ b/install-info/install-info.c
@@ -2529,9 +2529,9 @@ There is NO WARRANTY, to the extent permitted by law.\n"),

             if (section_empty)
               {
-                /* This gets rid of any trailing empty lines at the end
-                   of the section, and the title too. */
-                for (i = section->end_line; i >= section->start_line; i--)
+                /* This gets rid of any trailing empty lines at the end
+                   of the section, the title, and the preceding empty line. */ +                for (i = section->end_line; i >= section->start_line - 1; i--)
                   dir_lines[i - 1].delete = 1;
               }
           }
diff --git a/install-info/tests/ii-0047-expected-dir-file b/install-info/tests/ii-0047-expected-dir-file
index 9615d7528f..d2f31fd554 100644
--- a/install-info/tests/ii-0047-expected-dir-file
+++ b/install-info/tests/ii-0047-expected-dir-file
@@ -13,4 +13,3 @@ A few useful Info commands:
   `mTexinfo RET' visits the Texinfo manual, etc.

 * Menu:
-
======== end of patch ===========


Thank you,

John Wheeler



reply via email to

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