aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar dmarting <dmarting@google.com>2017-08-28 11:31:49 +0200
committerGravatar Vladimir Moskva <vladmos@google.com>2017-08-28 16:09:41 +0200
commit36178dddc45ee39e302516232c83b0fbc4c5dc37 (patch)
tree4e44cc265a99ed1bdb14bd9ff0966a9fd8ae4ab8
parent72ab9322ac4ea6b743bc304b7b5d05f8b5b56239 (diff)
Automated rollback of commit 39448ebab889a6b5b1ceabcf932adfec9098dfe7.
*** Reason for rollback *** Break docker builds *** Original change description *** Don't prepend ./ to filenames in pkg_tar rule Change-Id: Ib90ce99cc2e229bbe749130dbde517a075d6e333 PiperOrigin-RevId: 166679861
-rw-r--r--tools/build_defs/pkg/archive.py38
-rw-r--r--tools/build_defs/pkg/archive_test.py211
-rwxr-xr-xtools/build_defs/pkg/build_test.sh82
-rw-r--r--tools/build_defs/pkg/testdata/tar_test.tarbin10240 -> 10240 bytes
-rw-r--r--tools/build_defs/pkg/testdata/tar_test.tar.bz2bin165 -> 134 bytes
-rw-r--r--tools/build_defs/pkg/testdata/tar_test.tar.gzbin165 -> 158 bytes
-rw-r--r--tools/build_defs/pkg/testdata/tar_test.tar.xzbin212 -> 192 bytes
7 files changed, 115 insertions, 216 deletions
diff --git a/tools/build_defs/pkg/archive.py b/tools/build_defs/pkg/archive.py
index 259461e4f7..cf83aa997f 100644
--- a/tools/build_defs/pkg/archive.py
+++ b/tools/build_defs/pkg/archive.py
@@ -152,6 +152,8 @@ class TarFileWriter(object):
TarFileWriter.Error: when the recursion depth has exceeded the
`depth` argument.
"""
+ if not (name == '.' or name.startswith('/') or name.startswith('./')):
+ name = './' + name
if os.path.isdir(path):
# Remove trailing '/' (index -1 => last character)
if name[-1] == '/':
@@ -233,15 +235,15 @@ class TarFileWriter(object):
# Recurse into directory
self.add_dir(name, file_content, uid, gid, uname, gname, mtime, mode)
return
+ if not (name == '.' or name.startswith('/') or name.startswith('./')):
+ name = './' + name
if kind == tarfile.DIRTYPE:
name = name.rstrip('/')
if name in self.directories:
return
components = name.rsplit('/', 1)
- # Skip absolute files in root, e.g. /foo splits to "" and foo,
- # but /foo/bar splits to foo and bar
- if len(components) > 1 and components[0]:
+ if len(components) > 1:
d = components[0]
self.add_file(d,
tarfile.DIRTYPE,
@@ -300,6 +302,9 @@ class TarFileWriter(object):
Raises:
TarFileWriter.Error: if an error happens when uncompressing the tar file.
"""
+ if root and root[0] not in ['/', '.']:
+ # Root prefix should start with a '/', adds it if missing
+ root = '/' + root
compression = os.path.splitext(tar)[-1][1:]
if compression == 'tgz':
compression = 'gz'
@@ -342,24 +347,25 @@ class TarFileWriter(object):
tarinfo.gname = ''
name = tarinfo.name
+ if not name.startswith('/') and not name.startswith('.'):
+ name = './' + name
if root is not None:
- if not name.startswith('/'):
- name = os.path.join(root, name)
+ if name.startswith('.'):
+ name = '.' + root + name.lstrip('.')
# Add root dir with same permissions if missing. Note that
# add_file deduplicates directories and is safe to call here.
- self.add_file(
- root,
- tarfile.DIRTYPE,
- uid=tarinfo.uid,
- gid=tarinfo.gid,
- uname=tarinfo.uname,
- gname=tarinfo.gname,
- mtime=tarinfo.mtime,
- mode=0o755)
+ self.add_file('.' + root,
+ tarfile.DIRTYPE,
+ uid=tarinfo.uid,
+ gid=tarinfo.gid,
+ uname=tarinfo.uname,
+ gname=tarinfo.gname,
+ mtime=tarinfo.mtime,
+ mode=0o755)
# Relocate internal hardlinks as well to avoid breaking them.
link = tarinfo.linkname
- if not name.startswith('/') and tarinfo.type == tarfile.LNKTYPE:
- tarinfo.linkname = os.path.join(root, link)
+ if link.startswith('.') and tarinfo.type == tarfile.LNKTYPE:
+ tarinfo.linkname = '.' + root + link.lstrip('.')
tarinfo.name = name
if tarinfo.isfile():
diff --git a/tools/build_defs/pkg/archive_test.py b/tools/build_defs/pkg/archive_test.py
index 0855047149..729e533a2c 100644
--- a/tools/build_defs/pkg/archive_test.py
+++ b/tools/build_defs/pkg/archive_test.py
@@ -153,15 +153,6 @@ class TarFileWriterTest(unittest.TestCase):
self.assertSimpleFileContent(["./a", "./ab"])
self.assertSimpleFileContent(["./a", "./b", "./ab"])
- def testAddFileNoLeadingDotSlash(self):
- # If we don't use ./ when adding files, there shouldn't be a directory entry
- # for .
- with archive.TarFileWriter(self.tempfile) as f:
- f.add_file("a", content="a")
- f.add_file("b", content="b")
- content = [{"name": "a"}, {"name": "b"}]
- self.assertTarFileContent(self.tempfile, content)
-
def testDottedFiles(self):
with archive.TarFileWriter(self.tempfile) as f:
f.add_file("a")
@@ -171,48 +162,11 @@ class TarFileWriterTest(unittest.TestCase):
f.add_file("..e")
f.add_file(".f")
content = [
- {
- "name": "a"
- },
- {
- "name": "/b"
- },
- {
- "name": "."
- },
- {
- "name": "./c"
- },
- {
- "name": "./.d"
- },
- {
- "name": "..e"
- },
- {
- "name": ".f"
- },
+ {"name": "."}, {"name": "./a"}, {"name": "/b"}, {"name": "./c"},
+ {"name": "./.d"}, {"name": "./..e"}, {"name": "./.f"}
]
self.assertTarFileContent(self.tempfile, content)
- def testSubdirectories(self):
- with archive.TarFileWriter(self.tempfile) as f:
- f.add_file("a")
- f.add_file("b/c")
- f.add_file("c/d/e")
- f.add_file("./d")
- f.add_file("./e/f")
- f.add_file("./f/g/h")
- f.add_file("/g")
- f.add_file("/h/i")
- f.add_file("/i/j/k")
- expected_names = [
- "a", "b", "b/c", "c", "c/d", "c/d/e", ".", "./d", "./e", "./e/f", "./f",
- "./f/g", "./f/g/h", "/g", "/h", "/h/i", "/i", "/i/j", "/i/j/k"
- ]
- expected_content = [{"name": n} for n in expected_names]
- self.assertTarFileContent(self.tempfile, expected_content)
-
def testAddDir(self):
# For some strange reason, ending slash is stripped by the test
content = [
@@ -237,77 +191,36 @@ class TarFileWriterTest(unittest.TestCase):
def testMergeTar(self):
content = [
- {
- "name": "a",
- "data": "a"
- },
- {
- "name": "ab",
- "data": "ab"
- },
- ]
+ {"name": "./a", "data": "a"},
+ {"name": "./ab", "data": "ab"},
+ ]
for ext in ["", ".gz", ".bz2", ".xz"]:
with archive.TarFileWriter(self.tempfile) as f:
- f.add_tar(
- os.path.join(testenv.TESTDATA_PATH, "tar_test.tar" + ext),
- name_filter=lambda n: n != "b")
+ f.add_tar(os.path.join(testenv.TESTDATA_PATH, "tar_test.tar" + ext),
+ name_filter=lambda n: n != "./b")
self.assertTarFileContent(self.tempfile, content)
def testMergeTarRelocated(self):
content = [
- {
- "name": "foo",
- "mode": 0o755
- },
- {
- "name": "foo/a",
- "data": "a"
- },
- {
- "name": "foo/ab",
- "data": "ab"
- },
- ]
- with archive.TarFileWriter(self.tempfile) as f:
- f.add_tar(
- os.path.join(testenv.TESTDATA_PATH, "tar_test.tar"),
- name_filter=lambda n: n != "b",
- root="foo")
- self.assertTarFileContent(self.tempfile, content)
-
- def testMergeTarRelocatedAbsolute(self):
- content = [
- {
- "name": "/bar",
- "mode": 0o755
- },
- {
- "name": "/bar/a",
- "data": "a"
- },
- {
- "name": "/bar/ab",
- "data": "ab"
- },
- ]
+ {"name": ".", "mode": 0o755},
+ {"name": "./foo", "mode": 0o755},
+ {"name": "./foo/a", "data": "a"},
+ {"name": "./foo/ab", "data": "ab"},
+ ]
with archive.TarFileWriter(self.tempfile) as f:
- f.add_tar(
- os.path.join(testenv.TESTDATA_PATH, "tar_test.tar"),
- name_filter=lambda n: n != "b",
- root="/bar")
+ f.add_tar(os.path.join(testenv.TESTDATA_PATH, "tar_test.tar"),
+ name_filter=lambda n: n != "./b", root="/foo")
self.assertTarFileContent(self.tempfile, content)
def testAddingDirectoriesForFile(self):
with archive.TarFileWriter(self.tempfile) as f:
f.add_file("d/f")
content = [
- {
- "name": "d",
- "mode": 0o755
- },
- {
- "name": "d/f"
- },
+ {"name": ".",
+ "mode": 0o755},
+ {"name": "./d",
+ "mode": 0o755},
+ {"name": "./d/f"},
]
self.assertTarFileContent(self.tempfile, content)
@@ -328,30 +241,18 @@ class TarFileWriterTest(unittest.TestCase):
f.add_dir("a", a_dir)
f.add_file("a/b/f")
content = [
- {
- "name": "d",
- "mode": 0o755
- },
- {
- "name": "d/dir_file"
- },
- {
- "name": "d/f"
- },
- {
- "name": "a",
- "mode": 0o755
- },
- {
- "name": "a/dir_file"
- },
- {
- "name": "a/b",
- "mode": 0o755
- },
- {
- "name": "a/b/f"
- },
+ {"name": ".",
+ "mode": 0o755},
+ {"name": "./d",
+ "mode": 0o755},
+ {"name": "./d/dir_file"},
+ {"name": "./d/f"},
+ {"name": "./a",
+ "mode": 0o755},
+ {"name": "./a/dir_file"},
+ {"name": "./a/b",
+ "mode": 0o755},
+ {"name": "./a/b/f"},
]
self.assertTarFileContent(self.tempfile, content)
@@ -369,39 +270,23 @@ class TarFileWriterTest(unittest.TestCase):
f.add_file("x/y/f")
f.add_file("x", tarfile.DIRTYPE)
content = [
- {
- "name": "d",
- "mode": 0o755
- },
- {
- "name": "d/f"
- },
- {
- "name": "a",
- "mode": 0o755
- },
- {
- "name": "a/b",
- "mode": 0o755
- },
- {
- "name": "a/b/c",
- "mode": 0o755
- },
- {
- "name": "a/b/c/f"
- },
- {
- "name": "x",
- "mode": 0o755
- },
- {
- "name": "x/y",
- "mode": 0o755
- },
- {
- "name": "x/y/f"
- },
+ {"name": ".",
+ "mode": 0o755},
+ {"name": "./d",
+ "mode": 0o755},
+ {"name": "./d/f"},
+ {"name": "./a",
+ "mode": 0o755},
+ {"name": "./a/b",
+ "mode": 0o755},
+ {"name": "./a/b/c",
+ "mode": 0o755},
+ {"name": "./a/b/c/f"},
+ {"name": "./x",
+ "mode": 0o755},
+ {"name": "./x/y",
+ "mode": 0o755},
+ {"name": "./x/y/f"},
]
self.assertTarFileContent(self.tempfile, content)
diff --git a/tools/build_defs/pkg/build_test.sh b/tools/build_defs/pkg/build_test.sh
index 4e80d85263..1322f5006d 100755
--- a/tools/build_defs/pkg/build_test.sh
+++ b/tools/build_defs/pkg/build_test.sh
@@ -97,34 +97,36 @@ function get_changes() {
}
function assert_content() {
- local listing="etc/
-etc/nsswitch.conf
-usr/
-usr/titi
-usr/bin/
-usr/bin/java -> /path/to/bin/java"
+ local listing="./
+./etc/
+./etc/nsswitch.conf
+./usr/
+./usr/titi
+./usr/bin/
+./usr/bin/java -> /path/to/bin/java"
check_eq "$listing" "$(get_tar_listing $1)"
- check_eq "-rwxr-xr-x" "$(get_tar_permission $1 usr/titi)"
- check_eq "-rw-r--r--" "$(get_tar_permission $1 etc/nsswitch.conf)"
- check_eq "24/42" "$(get_numeric_tar_owner $1 etc/)"
- check_eq "24/42" "$(get_numeric_tar_owner $1 etc/nsswitch.conf)"
- check_eq "42/24" "$(get_numeric_tar_owner $1 usr/)"
- check_eq "42/24" "$(get_numeric_tar_owner $1 usr/titi)"
+ check_eq "-rwxr-xr-x" "$(get_tar_permission $1 ./usr/titi)"
+ check_eq "-rw-r--r--" "$(get_tar_permission $1 ./etc/nsswitch.conf)"
+ check_eq "24/42" "$(get_numeric_tar_owner $1 ./etc/)"
+ check_eq "24/42" "$(get_numeric_tar_owner $1 ./etc/nsswitch.conf)"
+ check_eq "42/24" "$(get_numeric_tar_owner $1 ./usr/)"
+ check_eq "42/24" "$(get_numeric_tar_owner $1 ./usr/titi)"
if [ -z "${2-}" ]; then
- check_eq "tata/titi" "$(get_tar_owner $1 etc/)"
- check_eq "tata/titi" "$(get_tar_owner $1 etc/nsswitch.conf)"
- check_eq "titi/tata" "$(get_tar_owner $1 usr/)"
- check_eq "titi/tata" "$(get_tar_owner $1 usr/titi)"
+ check_eq "tata/titi" "$(get_tar_owner $1 ./etc/)"
+ check_eq "tata/titi" "$(get_tar_owner $1 ./etc/nsswitch.conf)"
+ check_eq "titi/tata" "$(get_tar_owner $1 ./usr/)"
+ check_eq "titi/tata" "$(get_tar_owner $1 ./usr/titi)"
fi
}
function test_tar() {
- local listing="etc/
-etc/nsswitch.conf
-usr/
-usr/titi
-usr/bin/
-usr/bin/java -> /path/to/bin/java"
+ local listing="./
+./etc/
+./etc/nsswitch.conf
+./usr/
+./usr/titi
+./usr/bin/
+./usr/bin/java -> /path/to/bin/java"
for i in "" ".gz" ".bz2" ".xz"; do
assert_content "test-tar-${i:1}.tar$i"
# Test merging tar files
@@ -133,13 +135,18 @@ usr/bin/java -> /path/to/bin/java"
assert_content "test-tar-inclusion-${i:1}.tar" "true"
done;
- check_eq "nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-empty.tar)"
- check_eq "nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-none.tar)"
- check_eq "nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-etc.tar)"
- check_eq "etc/
-etc/nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-dot.tar)"
- check_eq "not-etc/
-not-etc/mapped-filename.conf" "$(get_tar_listing test-tar-files_dict.tar)"
+ check_eq "./
+./nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-empty.tar)"
+ check_eq "./
+./nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-none.tar)"
+ check_eq "./
+./nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-etc.tar)"
+ check_eq "./
+./etc/
+./etc/nsswitch.conf" "$(get_tar_listing test-tar-strip_prefix-dot.tar)"
+ check_eq "./
+./not-etc/
+./not-etc/mapped-filename.conf" "$(get_tar_listing test-tar-files_dict.tar)"
}
function test_deb() {
@@ -147,15 +154,16 @@ function test_deb() {
echo "Unable to run test for debian, no dpkg-deb!" >&2
return 0
fi
- local listing="etc/
-etc/nsswitch.conf
-usr/
-usr/titi
-usr/bin/
-usr/bin/java -> /path/to/bin/java"
+ local listing="./
+./etc/
+./etc/nsswitch.conf
+./usr/
+./usr/titi
+./usr/bin/
+./usr/bin/java -> /path/to/bin/java"
check_eq "$listing" "$(get_deb_listing test-deb.deb)"
- check_eq "-rwxr-xr-x" "$(get_deb_permission test-deb.deb usr/titi)"
- check_eq "-rw-r--r--" "$(get_deb_permission test-deb.deb etc/nsswitch.conf)"
+ check_eq "-rwxr-xr-x" "$(get_deb_permission test-deb.deb ./usr/titi)"
+ check_eq "-rw-r--r--" "$(get_deb_permission test-deb.deb ./etc/nsswitch.conf)"
get_deb_description test-deb.deb >$TEST_log
expect_log "Description: toto"
expect_log "Package: titi"
diff --git a/tools/build_defs/pkg/testdata/tar_test.tar b/tools/build_defs/pkg/testdata/tar_test.tar
index 4b915d63f6..70b043bd9d 100644
--- a/tools/build_defs/pkg/testdata/tar_test.tar
+++ b/tools/build_defs/pkg/testdata/tar_test.tar
Binary files differ
diff --git a/tools/build_defs/pkg/testdata/tar_test.tar.bz2 b/tools/build_defs/pkg/testdata/tar_test.tar.bz2
index ff5097f480..c6f7edf5a7 100644
--- a/tools/build_defs/pkg/testdata/tar_test.tar.bz2
+++ b/tools/build_defs/pkg/testdata/tar_test.tar.bz2
Binary files differ
diff --git a/tools/build_defs/pkg/testdata/tar_test.tar.gz b/tools/build_defs/pkg/testdata/tar_test.tar.gz
index 1b023dfd47..4b851716dd 100644
--- a/tools/build_defs/pkg/testdata/tar_test.tar.gz
+++ b/tools/build_defs/pkg/testdata/tar_test.tar.gz
Binary files differ
diff --git a/tools/build_defs/pkg/testdata/tar_test.tar.xz b/tools/build_defs/pkg/testdata/tar_test.tar.xz
index 5f3aac559d..1ea3c8b836 100644
--- a/tools/build_defs/pkg/testdata/tar_test.tar.xz
+++ b/tools/build_defs/pkg/testdata/tar_test.tar.xz
Binary files differ