umask option for tarfile extract

Faik Uygur faik at pardus.org.tr
Thu Jun 15 07:42:13 EDT 2006


Hello,

While extracting a tar file, is there a way to give an umask option for 
creating the non-existing upper directories of the file within the tar 
archive.

The default behaviour is to create the directories with 0777 permission bits.

Code taken from tarfile.py of python version 2.4.3:

        # Create all upper directories.
        upperdirs = os.path.dirname(targetpath)
        if upperdirs and not os.path.exists(upperdirs):
            ti = TarInfo()
            ti.name  = upperdirs
            ti.type  = DIRTYPE
            ti.mode  = 0777
		         ^^^^^^
            ti.mtime = tarinfo.mtime
            ti.uid   = tarinfo.uid
            ti.gid   = tarinfo.gid
            ti.uname = tarinfo.uname
            ti.gname = tarinfo.gname
            try:
                self._extract_member(ti, ti.name)
            except:
                pass

Regards,
- Faik



More information about the Python-list mailing list