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

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: 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
Index: client/isolateserver.py
diff --git a/client/isolateserver.py b/client/isolateserver.py
index 22ab89cdefabf1af5b24024fa862765f16ef9d3d..0e1ad010d2513d33da550d19e50c0fd1fdf01d99 100755
--- a/client/isolateserver.py
+++ b/client/isolateserver.py
@@ -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,6 +2113,20 @@ 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)
+ extractor = tarfile.TarFile(fileobj=srcfileobj)
M-A Ruel 2016/11/08 14:33:44 with tarfile.TarFile(fileobj=srcfileobj) as t: f
mithro 2016/11/09 00:19:35 Done.
+ for ti in extractor:
+ if not ti.isfile():
+ logging.warning(
+ "Nonfile (%s) object %s skipped", ti.type, ti.name)
+ continue
+ ifd = extractor.extractfile(ti)
+ fp = os.path.normpath(os.path.join(basedir, ti.name))
M-A Ruel 2016/11/08 14:33:44 if not fp.startswith(basedir): logging.error('ta
mithro 2016/11/09 00:19:35 Done.
+ file_path.ensure_tree(os.path.dirname(fp))
+ putfile(ifd, fp, 0700, ti.size)
+ extractor.close()
+
elif filetype == 'ar':
basedir = os.path.dirname(fullpath)
extractor = arfile.ArFileReader(srcfileobj, fullparse=False)

Powered by Google App Engine
This is Rietveld 408576698