summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-10-06 13:18:23 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-10-06 13:18:23 -0300
commit157449f214c71bb4234a96c0520eb4bb4f66fb32 (patch)
treed7f26494f00ac7c2a5925d7ce91180e26f016d0e /pkg
parenta57154017b47f14c51829bead81f7588f3db22ed (diff)
parenta13070c7259fcd76ff3903c59470ae4c60fe780e (diff)
Merge remote-tracking branch 'meskio/bug/6146_release_handle_removals' into develop
Diffstat (limited to 'pkg')
-rwxr-xr-xpkg/tuf/release.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/pkg/tuf/release.py b/pkg/tuf/release.py
index c4abcd0d..0e1c989c 100755
--- a/pkg/tuf/release.py
+++ b/pkg/tuf/release.py
@@ -29,7 +29,6 @@ import sys
from tuf.repository_tool import load_repository
from tuf.repository_tool import import_rsa_privatekey_from_file
-from tuf.repository_tool import import_rsa_publickey_from_file
"""
Days until the expiration of targets.json and snapshot.json. After this ammount
@@ -102,6 +101,8 @@ class Targets(object):
recursive_walk=True,
followlinks=True)
+ self._remove_obsolete_targets(target_list)
+
for target in target_list:
octal_file_permissions = oct(os.stat(target).st_mode)[3:]
custom_file_permissions = {
@@ -109,6 +110,26 @@ class Targets(object):
}
self._repo.targets.add_target(target, custom_file_permissions)
+ def _remove_obsolete_targets(self, target_list):
+ """
+ Remove obsolete targets from TUF targets
+
+ :param target_list: list of targets on full path comming from TUF
+ get_filepaths_in_directory
+ :type target_list: list(str)
+ """
+ targets_path = os.path.join(self._repo_path, 'targets')
+ relative_path_list = map(lambda t: t.split("/targets")[1], target_list)
+ removed_targets = (set(self._repo.targets.target_files.keys())
+ - set(relative_path_list))
+
+ for target in removed_targets:
+ target_rel_path = target
+ if target[0] == '/':
+ target_rel_path = target[1:]
+ target_path = os.path.join(targets_path, target_rel_path)
+ self._repo.targets.remove_target(target_path)
+
if __name__ == "__main__":
main()