Skip to content

Commit

Permalink
Removes symlink/file PULP_DISTRIBUTION.xml before writing a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
dkliban committed May 2, 2016
1 parent 5147c37 commit 16f5ac4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion plugins/pulp_rpm/plugins/distributors/yum/publish.py
Expand Up @@ -841,7 +841,15 @@ def _write_pulp_distribution_file(self, distro_files, old_xml_file_path):
element.text = distro_file

tree = cElementTree.ElementTree(new_xml_root)
tree.write(os.path.join(self.get_working_dir(), constants.DISTRIBUTION_XML))
distribution_xml_path = os.path.join(self.get_working_dir(), constants.DISTRIBUTION_XML)
try:
os.remove(distribution_xml_path)
except OSError as e:
if e.errno == os.errno.ENOENT:
pass
else:
raise e
tree.write(distribution_xml_path)

def _publish_distribution_packages_link(self, distribution_unit):
"""
Expand Down
5 changes: 4 additions & 1 deletion plugins/test/unit/plugins/distributors/yum/test_publish.py
Expand Up @@ -693,11 +693,14 @@ def assertPathNotPresent(self, root, path):
if child.text == path:
self.fail('path in XML: %s' % path)

def test_removes_file_entries(self):
@mock.patch('os.path.join')
@mock.patch('os.remove')
def test_removes_file_entries(self, mock_remove, mock_path_join):
"""
Make sure any paths in "distro_files" that are not present in the original XML get
filtered out.
"""
mock_path_join.side_effect = [self.target, 'fakepath']
paths = list(self.included_paths)
paths.append('remove/me')

Expand Down

0 comments on commit 16f5ac4

Please sign in to comment.