diff --git a/doc/changelog.txt b/doc/changelog.txt index 9e0b3f8..87a22f8 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -4,6 +4,8 @@ * Added option alias -v for --verbose. * Added --verbose option to create command. * Added support for Extract, list and test multiple archives. + * Fix permissions of extracted files: make them readable by the + current user. 0.5 "Vanishing Point" (released 4.3.2010) diff --git a/doc/patool.1 b/doc/patool.1 index 3f1d090..1fae8f9 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -50,6 +50,9 @@ directories. The patool program overcomes this problem by first extracting files to a unique (temporary) directory, and then moving its contents back if possible. This also prevents local files from being overwritten by mistake. +.br +All extracted files are checked that they are readable by the +current user. .TP \fB\-v\fP, \fB\-\-verbose\fP Be verbose when extracting (if the helper application supports it). diff --git a/doc/patool.txt b/doc/patool.txt index b02822f..18d479a 100644 --- a/doc/patool.txt +++ b/doc/patool.txt @@ -42,9 +42,11 @@ COMMANDS extracting files to a unique (temporary) directory, and then moving its contents back if possible. This also prevents local files from being overwritten by mistake. + All extracted files are checked that they are readable by the current + user. -v, --verbose - Be verbose when extracting (if the helper application supports + Be verbose when extracting (if the helper application supports it). --help Show help for this command. @@ -58,7 +60,7 @@ COMMANDS --help Show help for this command. create - Create an archive from given files. At least on of the given files to + Create an archive from given files. At least on of the given files to add to the archive has to exist. -v, --verbose diff --git a/doc/todo.txt b/doc/todo.txt index c3b7680..67b4199 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1 +1,3 @@ -- fix permissions (unreadable files) in extracted files (honor umask) +- Support ace (unace) archives. +- Support ar archives. +- Support lha archives. diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 33f3b6f..fed1646 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import os import shutil +import stat from patoolib import util # Supported archive commands @@ -309,8 +310,30 @@ def run_archive_cmdlist (archive_cmdlist): util.run(cmdlist, **runkwargs) +def make_file_readable (filename): + """Make file user readable if it is not a link.""" + if not os.path.islink(filename): + util.set_mode(filename, stat.S_IRUSR) + + +def make_dir_readable (filename): + """Make directory user readable and executable.""" + util.set_mode(filename, stat.S_IRUSR|stat.S_IXUSR) + + +def make_user_readable (directory): + """Make all files in given directory user readable. Also recurse into + subdirectories.""" + for root, dirs, files in os.walk(directory, onerror=util.log_error): + for filename in files: + make_file_readable(os.path.join(root, filename)) + for dirname in dirs: + make_dir_readable(os.path.join(root, dirname)) + + def cleanup_outdir (archive, outdir): """Cleanup outdir after extraction and return target file name.""" + make_user_readable(outdir) if outdir: # move single directory or file in outdir (res, msg) = move_outdir_orphan(outdir) diff --git a/patoolib/util.py b/patoolib/util.py index 597908d..9d7405c 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -215,6 +215,20 @@ def check_filename (filename): raise PatoolError("File `%s' not readable." % filename) +def set_mode (filename, flags): + """Set mode flags for given filename if not already set.""" + try: + mode = os.lstat(filename).st_mode + except OSError: + # ignore + return + if not (mode & flags): + try: + os.chmod(filename, flags | mode) + except OSError, msg: + log_error("could not set mode flags for `%s': %s" % (filename, msg)) + + def tmpdir (dir=None): """Return a temporary directory for extraction.""" return tempfile.mkdtemp(suffix='', prefix='Unpack_', dir=dir)