Skip to content

Commit

Permalink
Remove spurious decodes (follow-up to RB 1193)
Browse files Browse the repository at this point in the history
Testing Done:
Ran test_archive

Reviewed at https://rbcommons.com/s/twitter/r/1209/
  • Loading branch information
dturner-tw committed Oct 23, 2014
1 parent eaa2fc5 commit 39988f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/python/pants/fs/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from pants.util.contextutil import open_tar, open_zip
from pants.util.dirutil import safe_walk
from pants.util.strutil import ensure_text


class Archiver(AbstractClass):
Expand Down Expand Up @@ -48,9 +49,9 @@ def __init__(self, mode, extension):
self.extension = extension

def create(self, basedir, outdir, name, prefix=None):
tarpath = os.path.join(outdir, '%s.%s' % (name.decode('utf-8'), self.extension))
basedir = ensure_text(basedir)
tarpath = os.path.join(outdir, '%s.%s' % (ensure_text(name), self.extension))
with open_tar(tarpath, self.mode, dereference=True, errorlevel=1) as tar:
basedir = basedir.decode('utf-8')
tar.add(basedir, arcname=prefix or '.')
return tarpath

Expand Down Expand Up @@ -86,13 +87,13 @@ def create(self, basedir, outdir, name, prefix=None):
zippath = os.path.join(outdir, '%s.zip' % name)
with open_zip(zippath, 'w', compression=ZIP_DEFLATED) as zip:
for root, _, files in safe_walk(basedir):
root = root.decode('utf-8')
root = ensure_text(root)
for file in files:
file = file.decode('utf-8')
file = ensure_text(file)
full_path = os.path.join(root, file)
relpath = os.path.relpath(full_path, basedir)
if prefix:
relpath = os.path.join(prefix.decode('utf-8'), relpath)
relpath = os.path.join(ensure_text(prefix), relpath)
zip.write(full_path, relpath)
return zippath

Expand Down
6 changes: 3 additions & 3 deletions tests/python/pants_test/fs/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class ArchiveTest(unittest.TestCase):
def _listtree(self, root, empty_dirs):
listing = set()
for path, dirs, files in safe_walk(root):
relpath = os.path.normpath(os.path.relpath(path, root)).decode('utf-8')
relpath = os.path.normpath(os.path.relpath(path, root))
if empty_dirs:
listing.update(os.path.normpath(os.path.join(relpath, d.decode('utf-8'))) for d in dirs)
listing.update(os.path.normpath(os.path.join(relpath, f.decode('utf-8'))) for f in files)
listing.update(os.path.normpath(os.path.join(relpath, d)) for d in dirs)
listing.update(os.path.normpath(os.path.join(relpath, f)) for f in files)
return listing

def round_trip(self, archiver, empty_dirs):
Expand Down

0 comments on commit 39988f9

Please sign in to comment.