Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Archive::Tar directory permissions

by LiveandLearn2021 (Initiate)
on Jan 20, 2022 at 19:14 UTC ( #11140656=perlquestion: print w/replies, xml ) Need Help??

LiveandLearn2021 has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I am trying to determine if I'm encountering a bug or expected behavior with Archive::Tar. I've noticed that if I archive a directory such as /usr/include/sys/*.h that permissions are retained only for files underneath the sys directory. The permissions for /usr/include/sys change to the user that is extracting the files, including root. If the directory(/usr/include/sys) is owned by someone other than root it is not retained even if root does the extraction. If I use tar standalone to archive the directory then the permissions are retained for all directories. Is this to be expected? Additionally I've noticed that I cannot archive named pipes at all. The process will attempt to open the pipe and remain hung waiting on a response. This is the basic code I am using.
use Archive::Tar; $tar = Archive::Tar->new(); $tar->add_files(<"/usr/include/sys/*.h">) or die("Failed $!\n"); $tar->write("files.tar") or die("Failed $!\n");
These are the permissions on the original directories: ls -ld /usr drwxr-xr-x 54 root sys 69 Apr 9 2018 /usr ls -ld /usr/include drwxr-xr-x 117 root bin 436 Sep 25 22:10 /usr/include ls -ld /usr/include/sys drwxr-xr-x 25 root bin 628 Sep 25 22:09 /usr/include/sys When I extract the archive(as root) generated from my code I see these permissions: ls -ld usr drwxr-xr-x 3 root root 512 Jan 20 13:06 usr ls -ld usr/include drwxr-xr-x 3 root root 512 Jan 20 13:06 usr/include ls -ld usr/include/sys drwxr-xr-x 2 root root 11776 Jan 20 13:07 usr/include/sys Thank you for any assistance!

Replies are listed 'Best First'.
Re: Archive::Tar directory permissions
by kcott (Bishop) on Jan 20, 2022 at 22:14 UTC

    G'day LiveandLearn2021,

    Welcome to the Monastery.

    "I am trying to determine if I'm encountering a bug or expected behavior with Archive::Tar."

    I'd say that's expected behaviour. In "Archive::Tar - $Archive::Tar::SAME_PERMISSIONS" it says "The default is 1 for the root user and 0 for normal users.".

    [It's good that you've wrapped your code in <code>...</code> tags. Please also do this for any data and output (including exception messages). In this instance, your ls output is very difficult to read. Thankyou.]

    — Ken

      Thank you all for the suggestion and tips!
Re: Archive::Tar directory permissions
by Fletch (Bishop) on Jan 20, 2022 at 19:35 UTC

    The bits on $Archive::Tar::CHOWN, ::CHMOD, and SAME_PERMISSIONS in the Archive::Tar documentation may be relevant.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Archive::Tar directory permissions
by talexb (Chancellor) on Jan 21, 2022 at 16:18 UTC

    A formatting note for your post: you managed to wrap your code in code tags, but not the directory listing; the preview should have shown you that. The latter part of your post should like this:

      These are the permissions on the original directories:

      ls -ld /usr drwxr-xr-x 54 root sys 69 Apr 9 2018 /usr ls -ld /usr/include drwxr-xr-x 117 root bin 436 Sep 25 22:10 /usr/include ls -ld /usr/include/sys drwxr-xr-x 25 root bin 628 Sep 25 22:09 /usr/include/sys
      When I extract the archive(as root) generated from my code I see these permissions:
      ls -ld usr drwxr-xr-x 3 root root 512 Jan 20 13:06 usr ls -ld usr/include drwxr-xr-x 3 root root 512 Jan 20 13:06 usr/include ls -ld usr/include/sys drwxr-xr-x 2 root root 11776 Jan 20 13:07 usr/include/sys
      Thank you for any assistance!

    Do you see how this makes your question clearer?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11140656]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-05-26 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?