bsdtar: How to avoid overwriting existing file info?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












bsdtar has a -k (Do not overwrite existing files) option, which avoids changing the contents of any existing files, but it still overwrites the file info (e.g. permissions) with what is in the archive. Is there a way to make bsdtar completely skip overwriting existing files leaving file info intact the same way the --skip-old-files option works in GNU tar?



Here is a script that demonstrates the problem:



#!/usr/bin/env bash

echo -e "nCreate an archive with normal files"
rm -rf test-tar
mkdir test-tar
echo "TEST CONTENTS 1" > test-tar/1.txt
echo "TEST CONTENTS 2" > test-tar/2.txt
ls -la test-tar
bsdtar -czf test.tgz test-tar

echo -e "nChange contents and permissions of one of the files"
echo "MORE CONTENTS" >> test-tar/2.txt
chmod 000 test-tar/2.txt
ls -la test-tar

echo -e "nUntar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
bsdtar -xzkf test.tgz
ls -la test-tar
cat test-tar/2.txt

echo -e "nUntar the archive without -k"
bsdtar -xzf test.tgz
ls -la test-tar
cat test-tar/2.txt


Here is the script output:



Create an archive with normal files
total 16
drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt

Change contents and permissions of one of the files
total 16
drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
---------- 1 rbrainard wheel 30 Nov 29 17:53 2.txt

Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
total 16
drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
-rw-r--r-- 1 rbrainard wheel 30 Nov 29 17:53 2.txt
TEST CONTENTS 2
MORE CONTENTS

Untar the archive without -k
total 16
drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
-rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt
TEST CONTENTS 2


My bsdtar version is 3.3.2.







share|improve this question
























    up vote
    1
    down vote

    favorite












    bsdtar has a -k (Do not overwrite existing files) option, which avoids changing the contents of any existing files, but it still overwrites the file info (e.g. permissions) with what is in the archive. Is there a way to make bsdtar completely skip overwriting existing files leaving file info intact the same way the --skip-old-files option works in GNU tar?



    Here is a script that demonstrates the problem:



    #!/usr/bin/env bash

    echo -e "nCreate an archive with normal files"
    rm -rf test-tar
    mkdir test-tar
    echo "TEST CONTENTS 1" > test-tar/1.txt
    echo "TEST CONTENTS 2" > test-tar/2.txt
    ls -la test-tar
    bsdtar -czf test.tgz test-tar

    echo -e "nChange contents and permissions of one of the files"
    echo "MORE CONTENTS" >> test-tar/2.txt
    chmod 000 test-tar/2.txt
    ls -la test-tar

    echo -e "nUntar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
    bsdtar -xzkf test.tgz
    ls -la test-tar
    cat test-tar/2.txt

    echo -e "nUntar the archive without -k"
    bsdtar -xzf test.tgz
    ls -la test-tar
    cat test-tar/2.txt


    Here is the script output:



    Create an archive with normal files
    total 16
    drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
    drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt

    Change contents and permissions of one of the files
    total 16
    drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
    drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
    ---------- 1 rbrainard wheel 30 Nov 29 17:53 2.txt

    Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
    total 16
    drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
    drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
    -rw-r--r-- 1 rbrainard wheel 30 Nov 29 17:53 2.txt
    TEST CONTENTS 2
    MORE CONTENTS

    Untar the archive without -k
    total 16
    drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
    drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
    -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt
    TEST CONTENTS 2


    My bsdtar version is 3.3.2.







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      bsdtar has a -k (Do not overwrite existing files) option, which avoids changing the contents of any existing files, but it still overwrites the file info (e.g. permissions) with what is in the archive. Is there a way to make bsdtar completely skip overwriting existing files leaving file info intact the same way the --skip-old-files option works in GNU tar?



      Here is a script that demonstrates the problem:



      #!/usr/bin/env bash

      echo -e "nCreate an archive with normal files"
      rm -rf test-tar
      mkdir test-tar
      echo "TEST CONTENTS 1" > test-tar/1.txt
      echo "TEST CONTENTS 2" > test-tar/2.txt
      ls -la test-tar
      bsdtar -czf test.tgz test-tar

      echo -e "nChange contents and permissions of one of the files"
      echo "MORE CONTENTS" >> test-tar/2.txt
      chmod 000 test-tar/2.txt
      ls -la test-tar

      echo -e "nUntar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
      bsdtar -xzkf test.tgz
      ls -la test-tar
      cat test-tar/2.txt

      echo -e "nUntar the archive without -k"
      bsdtar -xzf test.tgz
      ls -la test-tar
      cat test-tar/2.txt


      Here is the script output:



      Create an archive with normal files
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt

      Change contents and permissions of one of the files
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      ---------- 1 rbrainard wheel 30 Nov 29 17:53 2.txt

      Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 30 Nov 29 17:53 2.txt
      TEST CONTENTS 2
      MORE CONTENTS

      Untar the archive without -k
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt
      TEST CONTENTS 2


      My bsdtar version is 3.3.2.







      share|improve this question












      bsdtar has a -k (Do not overwrite existing files) option, which avoids changing the contents of any existing files, but it still overwrites the file info (e.g. permissions) with what is in the archive. Is there a way to make bsdtar completely skip overwriting existing files leaving file info intact the same way the --skip-old-files option works in GNU tar?



      Here is a script that demonstrates the problem:



      #!/usr/bin/env bash

      echo -e "nCreate an archive with normal files"
      rm -rf test-tar
      mkdir test-tar
      echo "TEST CONTENTS 1" > test-tar/1.txt
      echo "TEST CONTENTS 2" > test-tar/2.txt
      ls -la test-tar
      bsdtar -czf test.tgz test-tar

      echo -e "nChange contents and permissions of one of the files"
      echo "MORE CONTENTS" >> test-tar/2.txt
      chmod 000 test-tar/2.txt
      ls -la test-tar

      echo -e "nUntar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
      bsdtar -xzkf test.tgz
      ls -la test-tar
      cat test-tar/2.txt

      echo -e "nUntar the archive without -k"
      bsdtar -xzf test.tgz
      ls -la test-tar
      cat test-tar/2.txt


      Here is the script output:



      Create an archive with normal files
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt

      Change contents and permissions of one of the files
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      ---------- 1 rbrainard wheel 30 Nov 29 17:53 2.txt

      Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 30 Nov 29 17:53 2.txt
      TEST CONTENTS 2
      MORE CONTENTS

      Untar the archive without -k
      total 16
      drwxr-xr-x 4 rbrainard wheel 136 Nov 29 17:53 .
      drwxr-xr-x 14 rbrainard wheel 476 Nov 29 17:53 ..
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 1.txt
      -rw-r--r-- 1 rbrainard wheel 16 Nov 29 17:53 2.txt
      TEST CONTENTS 2


      My bsdtar version is 3.3.2.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 29 '17 at 9:59









      ryanbrainard

      1264




      1264




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          It turned out that this is a bug. I cross-posted it to libarchive-discuss and one of the maintainers responded as such. Filed an issue at: https://github.com/libarchive/libarchive/issues/972






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407696%2fbsdtar-how-to-avoid-overwriting-existing-file-info%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            It turned out that this is a bug. I cross-posted it to libarchive-discuss and one of the maintainers responded as such. Filed an issue at: https://github.com/libarchive/libarchive/issues/972






            share|improve this answer
























              up vote
              1
              down vote



              accepted










              It turned out that this is a bug. I cross-posted it to libarchive-discuss and one of the maintainers responded as such. Filed an issue at: https://github.com/libarchive/libarchive/issues/972






              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                It turned out that this is a bug. I cross-posted it to libarchive-discuss and one of the maintainers responded as such. Filed an issue at: https://github.com/libarchive/libarchive/issues/972






                share|improve this answer












                It turned out that this is a bug. I cross-posted it to libarchive-discuss and one of the maintainers responded as such. Filed an issue at: https://github.com/libarchive/libarchive/issues/972







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 4 '17 at 3:43









                ryanbrainard

                1264




                1264



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407696%2fbsdtar-how-to-avoid-overwriting-existing-file-info%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay