[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tar-bug
Subject:    [Bug-tar] The --exclude-ignore option acts recursively, while it shouldn't
From:       Kirill Pushkaryov <cyril.pushkaryov () yandex ! ru>
Date:       2016-10-30 4:21:27
Message-ID: 8e2dc224-b815-d1a9-a0af-d6fea6cf9431 () yandex ! ru
[Download RAW message or body]

Hello!

I've found that patterns from a file specified via the --exclude-ignore 
option are excluded from subdirectories too, which contradicts the 
manual. The problem was encountered in tar 1.28 and confirmed in the 
latest tar from the git.savannah.gnu.org/tar.git.

The manual says (6.4):

"`--exclude-ignore=file'

    Before dumping a directory, |tar| checks if it contains file. If so,
    exclusion patterns are read from this file. The patterns affect only
    the directory itself."

How to reproduce:

    mkdir test test/a
    touch test/b test/a/b
    echo b > test/.ign
    tar -cvf test.tar --exclude-ignore=.ign test

Current result:

    test/
    test/.ign
    test/a/

Expected result: test/a/b must not be excluded.

I'm not familiar with the source code, but after quick debugging I 
suspect a bug in info_attach_exclist() (exclist.c:117 from the git HEAD 
(1d2674b)):

       ent = xmalloc (sizeof (*ent));
       ent->excluded = ex;
       ent->flags = file->flags == EXCL_DEFAULT
                    ? file->flags : vcsfile->flags;
       ent->prev = tail;
       ent->next = NULL;

It looks like file->flags are propagated to ent->flags only when they're 
equal to EXCL_DEFAULT (0x00), so EXCL_NON_RECURSIVE (0x02) pertaining to 
--exclude-ignore is dropped, which prevents the condition in 
excluded_name() (exclist.c:172) from skipping non-recursive entries from 
distant ancestors.

-- 

WBR, Kirill Pushkaryov.


[Attachment #3 (text/html)]

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hello!</p>
    <p>I've found that patterns from a file specified via the
      --exclude-ignore option are excluded from subdirectories too,
      which contradicts the manual. The problem was encountered in tar
      1.28 and confirmed in the latest tar from the
      git.savannah.gnu.org/tar.git.<br>
    </p>
    <p>The manual says (6.4):</p>
    <p>"<samp>`--exclude-ignore=<var>file</var>'</samp></p>
    <dl compact="compact">
      <dd>
        <p>Before dumping a directory, <code>tar</code> checks if it
          contains <var>file</var>. If so, exclusion patterns are read
          from this file. The patterns affect only the directory itself."</p>
      </dd>
    </dl>
    <p>How to reproduce:</p>
    <blockquote>
      <p>mkdir test test/a<br>
        touch test/b test/a/b<br>
        echo b &gt; test/.ign<br>
        tar -cvf test.tar --exclude-ignore=.ign test</p>
    </blockquote>
    <p>Current result:</p>
    <blockquote>
      <p>test/<br>
        test/.ign<br>
        test/a/</p>
    </blockquote>
    <p>Expected result: test/a/b must not be excluded.</p>
    <p>I'm not familiar with the source code, but after quick debugging
      I suspect a bug in info_attach_exclist() (exclist.c:117 from the
      git HEAD (1d2674b)):</p>
    <p>          ent = xmalloc (sizeof (*ent));<br>
                ent-&gt;excluded = ex;<br>
                ent-&gt;flags = file-&gt;flags == EXCL_DEFAULT<br>
                                          ? file-&gt;flags : vcsfile-&gt;flags;<br>
                ent-&gt;prev = tail;<br>
                ent-&gt;next = NULL;<br>
    </p>
    <p>It looks like file-&gt;flags are propagated to ent-&gt;flags only
      when they're equal to EXCL_DEFAULT (0x00), so EXCL_NON_RECURSIVE
      (0x02) pertaining to --exclude-ignore is dropped, which prevents
      the condition in excluded_name() (exclist.c:172) from skipping
      non-recursive entries from distant ancestors.</p>
    <p>-- <br>
    </p>
    <p>WBR, Kirill Pushkaryov.<br>
    </p>
  </body>
</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic