Skip to content

Instantly share code, notes, and snippets.

@vbatts
Last active August 29, 2015 14:01
Show Gist options
  • Save vbatts/4432cfdba67ec5861662 to your computer and use it in GitHub Desktop.
Save vbatts/4432cfdba67ec5861662 to your computer and use it in GitHub Desktop.
reproducing the failure of value.decode("utf8") in python https://github.com/akheron/cpython/blob/2.7/Lib/tarfile.py#L1393
FROM fedora:latest
RUN yum install -y attr
RUN touch file
RUN setcap 'cap_setgid,cap_setuid+ep' ./file && getcap ./file
#!/bin/sh
set -e
cwd=$(pwd)
d=${D:-$(mktemp -d)}
if [ ${#D} -eq 0 ] ; then
# this base image is pretty arbitrary
docker pull fedora:latest
# build an image with xattr info set, and tools to get the sum (of itself)
docker build -t test_xattr .
# produce the tar layers of this image with xattr information
docker save test_xattr | tar -C ${d} -x
fi
export REGISTRY_DIR=${cwd}/docker-registry
if [ ! -d ${REGISTRY_DIR} ] ; then
git clone [email protected]:dotcloud/docker-registry.git
fi
pushd ${d}
for path in $(find . -mindepth 1 -type d) ; do
layer="./${path}/layer.tar"
json="./${path}/json"
python ${cwd}/tarsum.py ${json} ${layer}
done
popd
rm -rf ${d}
#!/usr/bin/env python
import sys
import os
import traceback
sys.path.insert(0, os.getenv("REGISTRY_DIR") + '/docker_registry/lib')
sys.path.insert(0, os.getenv("REGISTRY_DIR") + '/docker_registry')
import checksums
import tarfile
def main(args):
if len(args) < 3:
print "%s <jsonfile> <tarfile>" % args[0]
return
json_file = args[1]
tar_file = args[2]
jh = open(json_file)
th = open(tar_file)
tarsum = checksums.TarSum(jh.read())
try:
tar = tarfile.open(mode='r|*', fileobj=th)
for member in tar:
tarsum.append(member, tar)
except BaseException as e:
print "Unexpected error:", sys.exc_info()[0]
print sys.exc_info()
print e
print traceback.format_exc()
exit(1)
print tarsum.compute()
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment