diff options
author | Damien Martin-Guillerez <dmarting@google.com> | 2015-09-24 18:25:10 +0000 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@google.com> | 2015-09-25 14:40:10 +0000 |
commit | 7d48f19585db97ffcc55bef0ff557b86df45d65f (patch) | |
tree | 40626bca1dbcb2100f674409cd46e41079c6d2b7 /tools | |
parent | ed9281682ad01127c084cf9d181feecb604ca83e (diff) |
[Docker] Correctly append ./ prefix to dotted files in archives
Previously, dotted files were though of having the './' prefix.
--
MOS_MIGRATED_REVID=103864015
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build_defs/docker/archive.py | 4 | ||||
-rw-r--r-- | tools/build_defs/docker/archive_test.py | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/tools/build_defs/docker/archive.py b/tools/build_defs/docker/archive.py index a8234e136f..5e7eaf33cf 100644 --- a/tools/build_defs/docker/archive.py +++ b/tools/build_defs/docker/archive.py @@ -128,7 +128,7 @@ class TarFileWriter(object): TarFileWriter.Error: when the recursion depth has exceeded the `depth` argument. """ - if not name.startswith('.') and not name.startswith('/'): + if not (name == '.' or name.startswith('/') or name.startswith('./')): name = './' + name if os.path.isdir(path): # Remove trailing '/' (index -1 => last character) @@ -183,7 +183,7 @@ class TarFileWriter(object): # Recurse into directory self.add_dir(name, file_content, uid, gid, uname, gname, mtime, mode) return - if not name.startswith('.') and not name.startswith('/'): + if not (name == '.' or name.startswith('/') or name.startswith('./')): name = './' + name tarinfo = tarfile.TarInfo(name) tarinfo.mtime = mtime diff --git a/tools/build_defs/docker/archive_test.py b/tools/build_defs/docker/archive_test.py index 7f0a254322..620f7fda1b 100644 --- a/tools/build_defs/docker/archive_test.py +++ b/tools/build_defs/docker/archive_test.py @@ -153,6 +153,24 @@ class TarFileWriterTest(unittest.TestCase): self.assertSimpleFileContent(["./a", "./ab"]) self.assertSimpleFileContent(["./a", "./b", "./ab"]) + def testDottedFiles(self): + with archive.TarFileWriter(self.tempfile) as f: + f.add_file("a") + f.add_file("/b") + f.add_file("./c") + f.add_file("./.d") + f.add_file("..e") + f.add_file(".f") + content = [ + {"name": "./a"}, + {"name": "/b"}, + {"name": "./c"}, + {"name": "./.d"}, + {"name": "./..e"}, + {"name": "./.f"} + ] + self.assertTarFileContent(self.tempfile, content) + def testAddDir(self): # For some strange reason, ending slash is stripped by the test content = [ |