Skip to content

Commit

Permalink
Merge branch 'release/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmatthews committed Mar 20, 2017
2 parents 95b18eb + 112f179 commit 0dc7117
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Change Log
All notable changes to the COT project will be documented in this file.
This project adheres to `Semantic Versioning`_.

`2.0.2`_ - 2017-03-20
---------------------

**Fixed**

- Path normalization of output file resulted in COT failing to detect the
case of self-overwriting an OVA, resulting in file corruption (`#66`_).
Improved detection of self-overwriting cases including relative vs.
absolute paths, symlinks, and hardlinks.

`2.0.1`_ - 2017-03-17
---------------------

Expand Down Expand Up @@ -752,6 +762,7 @@ Initial public release.
.. _#63: https://github.com/glennmatthews/cot/issues/63
.. _#64: https://github.com/glennmatthews/cot/issues/64
.. _#65: https://github.com/glennmatthews/cot/issues/65
.. _#66: https://github.com/glennmatthews/cot/issues/66

.. _Semantic Versioning: http://semver.org/
.. _`PEP 8`: https://www.python.org/dev/peps/pep-0008/
Expand Down Expand Up @@ -784,6 +795,7 @@ Initial public release.
.. _verboselogs: https://verboselogs.readthedocs.io/en/latest/

.. _Unreleased: https://github.com/glennmatthews/cot/compare/master...develop
.. _2.0.2: https://github.com/glennmatthews/cot/compare/v2.0.1...v2.0.2
.. _2.0.1: https://github.com/glennmatthews/cot/compare/v2.0.0...v2.0.1
.. _2.0.0: https://github.com/glennmatthews/cot/compare/v1.9.1...v2.0.0
.. _1.9.1: https://github.com/glennmatthews/cot/compare/v1.9.0...v1.9.1
Expand Down
14 changes: 11 additions & 3 deletions COT/vm_description/ovf/ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2640,12 +2640,20 @@ def tar(self, ovf_descriptor, tar_file):

(prefix, _) = os.path.splitext(ovf_descriptor)

if self.input_file == tar_file:
# Issue #66 - need to detect any of the possible scenarios:
# 1) output path and input path are the same real path
# (not just string-equal!)
# 2) output file and input file are the same file (including links)
# but not error out if (common case) output_file doesn't exist yet.
if (os.path.realpath(self.input_file) == os.path.realpath(tar_file) or
(os.path.exists(tar_file) and
os.path.samefile(self.input_file, tar_file))):
# We're about to overwrite the input OVA with a new OVA.
# (Python tarfile module doesn't support in-place edits.)
# Any files that we need to carry over need to be extracted NOW!
logger.verbose("Extracting files from %s before overwriting it.",
self.input_file)
logger.info(
"Input OVA will be overwritten. Extracting files from %s to"
" working directory before overwriting it.", self.input_file)
for filename in self._file_references:
file_ref = self._file_references[filename]
if file_ref.file_path is None:
Expand Down
18 changes: 17 additions & 1 deletion COT/vm_description/ovf/tests/test_ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,27 @@ def test_tar_untar(self):
ovf.destroy()

# Read OVA and overwrite itself
ova = OVF(os.path.join(self.temp_dir, "temp.ova"),
# Issue #66 resulted from the two strings not being identical
# So mix relative and absolute paths:
os.chdir(self.temp_dir)
ova = OVF("temp.ova",
os.path.join(self.temp_dir, "temp.ova"))
ova.write()
ova.destroy()

# Another permutation of issue #66 - output file is a
# symlink to input file
os.symlink("temp.ova", "symlink.ova")
ova = OVF("temp.ova", "symlink.ova")
ova.write()
ova.destroy()

# A third permutation - output file is hardlink to input
os.link("temp.ova", "hardlink.ova")
ova = OVF("temp.ova", "hardlink.ova")
ova.write()
ova.destroy()

# Read OVA and write to OVF
ovf2 = OVF(os.path.join(self.temp_dir, "temp.ova"),
os.path.join(self.temp_dir, "input.ovf"))
Expand Down
2 changes: 2 additions & 0 deletions docs/thanks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ We would like to thank:
* Chandu Gutti
* Jeff Haag
* Jeff Loughridge
* Vincent Wenshi Lv
* Roger Melton
* Jonathan Muslow
* Scott O'Donnell
* Rick Ogg
Expand Down

0 comments on commit 0dc7117

Please sign in to comment.