views:

298

answers:

1

Just a Question Regarding unix and PHP today.

What I am doing on my PHP is using the Unix system to untar a tarred file.

exec("tar -xzf foo.tar.gz");

Generally everything works fine until I run into this particular foo.tar.gz, which has a file system as follows:

Applications/
Library/
Systems/

After running the tar command, it seems that the file permissions get changed to 644 (instead of 755).

This causes Permission denied (errno 13) and therefore disabling most of my code. (I'm guessing from lack of privileges)

Any way I can stop this tar command completely ruining my permissions?

Thanks.

Oh and this seems to only happen when I have a foo.tar.gz file that Has this particular file system. Anything else and I'm good.

A: 

If you want to keep the permissions on files then you have to add the -p (or --preserve-permissions or --same-permissions) switch when extracting the tarball. From the tar man pages :

--preserve-permissions
--same-permissions
-p
    When `tar' is extracting an archive, it normally subtracts the
    users' umask from the permissions specified in the archive and
    uses that number as the permissions to create the destination
    file.  Specifying this option instructs `tar' that it should use
    the permissions directly from the archive.

So PHP code should be :

exec("tar -xzfp foo.tar.gz");
wimvds
No good. It doesn't seem to be extracting it at all now."tar -xpzf" works, but I still get the permission errors.
Moe
Oh, and it Seems to change the permissions in the current directory. Is there anyway I can extract a tar into a different directory, then Chmod that back to 755?
Moe
wimvds
Yes, they match - What is happening most importantly, is the directory I am in also changes to 644, not only the files. That's the weirdest part.
Moe