@@ -352,15 +352,8 @@ the target filepaths to metadata.
352
352
# in targets metadata.
353
353
>> > repository = load_repository(' repository' )
354
354
355
- # get_filepaths_in_directory() returns a list of file paths in a directory. It
356
- # can also return files in sub-directories if 'recursive_walk' is True.
357
- >> > list_of_targets = repository.get_filepaths_in_directory(
358
- ... " repository/targets/" , recursive_walk = False , followlinks = True )
359
-
360
- # Note: Since we set the 'recursive_walk' argument to false, the 'myproject'
361
- # sub-directory is excluded from 'list_of_targets'.
362
- >> > list_of_targets
363
- [' /path/to/repository/targets/file2.txt' , ' /path/to/repository/targets/file1.txt' , ' /path/to/repository/targets/file3.txt' ]
355
+ # Create a list of all targets in the directory.
356
+ >> > list_of_targets = [' file1.txt' , ' file2.txt' , ' file3.txt' ]
364
357
365
358
# Add the list of target paths to the metadata of the top-level Targets role.
366
359
# Any target file paths that might already exist are NOT replaced, and
@@ -376,10 +369,12 @@ the target filepaths to metadata.
376
369
# (octal number specifying file access for owner, group, others e.g., 0755) is
377
370
# added alongside the default fileinfo. All target objects in metadata include
378
371
# the target's filepath, hash, and length.
372
+ # Note: target path passed to add_target() method has to be relative
373
+ # to the targets directory or an exception is raised.
379
374
>> > target4_filepath = os.path.abspath(" repository/targets/myproject/file4.txt" )
380
375
>> > octal_file_permissions = oct (os.stat(target4_filepath).st_mode)[4 :]
381
376
>> > custom_file_permissions = {' file_permissions' : octal_file_permissions}
382
- >> > repository.targets.add_target(target4_filepath , custom_file_permissions)
377
+ >> > repository.targets.add_target(' myproject/file4.txt ' , custom_file_permissions)
383
378
```
384
379
385
380
The private keys of roles affected by the changes above must now be imported and
@@ -498,7 +493,6 @@ targets and generate signed metadata.
498
493
499
494
# Make a delegation (delegate trust of 'myproject/*.txt' files) from "targets"
500
495
# to "unclaimed", where "unclaimed" initially contains zero targets.
501
- # NOTE : Please ignore the warning about the path pattern's location (see #963)
502
496
>> > repository.targets.delegate(' unclaimed' , [public_unclaimed_key], [' myproject/*.txt' ])
503
497
504
498
# Thereafter, we can access the delegated role by its name to e.g. add target
@@ -635,8 +629,7 @@ to some role.
635
629
>> > repository.targets(' unclaimed' ).remove_target(" myproject/file4.txt" )
636
630
637
631
# Get a list of target paths for the hashed bins.
638
- >> > targets = repository.get_filepaths_in_directory(
639
- ... ' repository/targets/myproject' , recursive_walk = True )
632
+ >> > targets = [' myproject/file4.txt' ]
640
633
641
634
# Delegate trust to 32 hashed bin roles. Each role is responsible for the set
642
635
# of target files, determined by the path hash prefix. TUF evenly distributes
0 commit comments