@@ -46,7 +46,7 @@ def add_entries(self, entries):
4646
4747 def add_files (
4848 self , * paths , flags = 0 , lookup = False , pathname = None , recursive = True ,
49- ** attributes
49+ symlink_mode = None , ** attributes
5050 ):
5151 """Read files through the OS and add them to the archive.
5252
@@ -63,6 +63,9 @@ def add_files(
6363 recursive (bool):
6464 when False, if a path in `paths` is a directory,
6565 only the directory itself is added.
66+ symlink_mode (Literal['hybrid', 'logical', 'physical'] | None):
67+ how symbolic links should be handled; see `man archive_read_disk`
68+ for meanings
6669 attributes (dict): passed to `ArchiveEntry.modify()`
6770
6871 Raises:
@@ -75,10 +78,23 @@ def add_files(
7578 if block_size <= 0 :
7679 block_size = 10240 # pragma: no cover
7780
81+ set_symlink_mode = None
82+ if symlink_mode :
83+ try :
84+ set_symlink_mode = getattr (
85+ ffi , f'read_disk_set_symlink_{ symlink_mode } '
86+ )
87+ except AttributeError :
88+ raise ValueError (
89+ f"symlink_mode value { symlink_mode !r} is invalid"
90+ ) from None
91+
7892 entry = ArchiveEntry (header_codec = self .header_codec )
7993 entry_p = entry ._entry_p
8094 for path in paths :
8195 with new_archive_read_disk (path , flags , lookup ) as read_p :
96+ if set_symlink_mode :
97+ set_symlink_mode (read_p )
8298 while 1 :
8399 r = read_next_header2 (read_p , entry_p )
84100 if r == ARCHIVE_EOF :
0 commit comments