Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: client/isolateserver.py

Issue 2484133002: luci-py/isolateserver.py: Add support for tar archives when downloading. (Closed) Base URL: https://github.com/luci/luci-py.git@master
Patch Set: Rebase onto master. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/isolated_format.py ('k') | client/tests/archive.tar » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/isolateserver.py
diff --git a/client/isolateserver.py b/client/isolateserver.py
index 22ab89cdefabf1af5b24024fa862765f16ef9d3d..1c04303a334a75e1cf994bd67823f5a5ec7535bb 100755
--- a/client/isolateserver.py
+++ b/client/isolateserver.py
@@ -5,7 +5,7 @@
"""Archives a set of files or directories to an Isolate Server."""
-__version__ = '0.6.0'
+__version__ = '0.7.0'
import base64
import errno
@@ -18,6 +18,7 @@ import re
import signal
import stat
import sys
+import tarfile
import tempfile
import threading
import time
@@ -169,6 +170,11 @@ def fileobj_path(fileobj):
if not isinstance(name, unicode):
name = name.decode(sys.getfilesystemencoding())
+ # fs.exists requires an absolute path, otherwise it will fail with an
+ # assertion error.
+ if not os.path.isabs(name):
+ return
+
if fs.exists(name):
return name
@@ -2107,11 +2113,33 @@ def fetch_isolated(isolated_hash, storage, cache, outdir, use_symlinks):
srcfileobj, fullpath, file_mode,
use_symlink=use_symlinks)
+ elif filetype == 'tar':
+ basedir = os.path.dirname(fullpath)
+ with tarfile.TarFile(fileobj=srcfileobj) as extractor:
+ for ti in extractor:
+ if not ti.isfile():
+ logging.warning(
+ 'Path(%r) is nonfile (%s), skipped',
+ ti.name, ti.type)
+ continue
+ fp = os.path.normpath(os.path.join(basedir, ti.name))
+ if not fp.startswith(basedir):
+ logging.error(
+ 'Path(%r) is outside root directory',
+ fp)
+ ifd = extractor.extractfile(ti)
+ file_path.ensure_tree(os.path.dirname(fp))
+ putfile(ifd, fp, 0700, ti.size)
+
elif filetype == 'ar':
basedir = os.path.dirname(fullpath)
extractor = arfile.ArFileReader(srcfileobj, fullparse=False)
for ai, ifd in extractor:
fp = os.path.normpath(os.path.join(basedir, ai.name))
+ if not fp.startswith(basedir):
+ logging.error(
+ 'Path(%r) is outside root directory',
+ fp)
file_path.ensure_tree(os.path.dirname(fp))
putfile(ifd, fp, 0700, ai.size)
« no previous file with comments | « client/isolated_format.py ('k') | client/tests/archive.tar » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698