Make extracted files user readable.
This commit is contained in:
parent
9ee4f65b90
commit
670d5df652
|
@ -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)
|
||||
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
- fix permissions (unreadable files) in extracted files (honor umask)
|
||||
- Support ace (unace) archives.
|
||||
- Support ar archives.
|
||||
- Support lha archives.
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue