@@ -125,12 +125,13 @@ def _generate_and_write_metadata(rolename, metadata_filename,
125125
126126
127127 elif rolename == 'snapshot' :
128+ metadata , fileinfodict = generate_snapshot_metadata (metadata_directory ,
129+ roleinfo ['version' ], roleinfo ['expires' ],
130+ storage_backend , consistent_snapshot , repository_name ,
131+ use_length = use_snapshot_length , use_hashes = use_snapshot_hashes )
132+
128133 if snapshot_merkle :
129- root , leaves , metadata = generate_snapshot_metadata (metadata_directory ,
130- roleinfo ['version' ], roleinfo ['expires' ],
131- storage_backend , consistent_snapshot , repository_name ,
132- use_length = use_snapshot_length , use_hashes = use_snapshot_hashes ,
133- snapshot_merkle = True )
134+ root , leaves = _build_merkle_tree (fileinfodict )
134135
135136 # Add the merkle tree root hash to the timestamp roleinfo
136137 timestamp_roleinfo = tuf .roledb .get_roleinfo ('timestamp' , repository_name )
@@ -141,12 +142,6 @@ def _generate_and_write_metadata(rolename, metadata_filename,
141142
142143 _write_merkle_paths (root , leaves , storage_backend , metadata_directory )
143144
144- else :
145- metadata = generate_snapshot_metadata (metadata_directory ,
146- roleinfo ['version' ], roleinfo ['expires' ],
147- storage_backend , consistent_snapshot , repository_name ,
148- use_length = use_snapshot_length , use_hashes = use_snapshot_hashes )
149-
150145
151146 _log_warning_if_expires_soon (SNAPSHOT_FILENAME , roleinfo ['expires' ],
152147 SNAPSHOT_EXPIRES_WARN_SECONDS )
@@ -1707,6 +1702,12 @@ def _write_merkle_paths(root, leaves, storage_backend, merkle_directory):
17071702 # the client and used for verification of the tree. For each
17081703 # step in the path, keep track of both the sibling node and
17091704 # Whether this is a left or a right child.
1705+
1706+ # Before writing each leaf, make sure the storage_backend
1707+ # is instantiated
1708+ if storage_backend is None :
1709+ storage_backend = securesystemslib .storage .FilesystemBackend ()
1710+
17101711 for l in leaves :
17111712 merkle_path = {}
17121713 current_node = l
@@ -1740,8 +1741,6 @@ def _write_merkle_paths(root, leaves, storage_backend, merkle_directory):
17401741 leaf_contents = l .contents ,
17411742 merkle_path = merkle_path ,
17421743 path_directions = path_directions )
1743- if storage_backend is None :
1744- storage_backend = securesystemslib .storage .FilesystemBackend ()
17451744 file_content = _get_written_metadata (file_contents )
17461745 file_object = tempfile .TemporaryFile ()
17471746 file_object .write (file_content )
@@ -1778,7 +1777,7 @@ def print_merkle_tree(root):
17781777
17791778def generate_snapshot_metadata (metadata_directory , version , expiration_date ,
17801779 storage_backend , consistent_snapshot = False ,
1781- repository_name = 'default' , use_length = False , use_hashes = False , snapshot_merkle = False ):
1780+ repository_name = 'default' , use_length = False , use_hashes = False ):
17821781 """
17831782 <Purpose>
17841783 Create the snapshot metadata. The minimum metadata must exist (i.e.,
@@ -1829,11 +1828,6 @@ def generate_snapshot_metadata(metadata_directory, version, expiration_date,
18291828 Read more at section 5.6 from the Mercury paper:
18301829 https://www.usenix.org/conference/atc17/technical-sessions/presentation/kuppusamy
18311830
1832- snapshot_merkle:
1833- Whether to generate snapshot merkle files in addition to snapshot.json
1834- metadata. If this is true, this function will return the root and leaves
1835- of the merkle tree in addition to the snapshot metadata.
1836-
18371831 <Exceptions>
18381832 securesystemslib.exceptions.FormatError, if the arguments are improperly
18391833 formatted.
@@ -1929,10 +1923,7 @@ def generate_snapshot_metadata(metadata_directory, version, expiration_date,
19291923 expires = expiration_date ,
19301924 meta = fileinfodict )
19311925
1932- if snapshot_merkle :
1933- root , leaves = _build_merkle_tree (fileinfodict )
1934- return root , leaves , metadata
1935- return metadata
1926+ return metadata , fileinfodict
19361927
19371928
19381929
0 commit comments