Skip to content

Commit 232da89

Browse files
committed
add test of symlink_mode argument
1 parent f170918 commit 232da89

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_rwx.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io
44
import json
5+
import os
56

67
import libarchive
78
from libarchive.entry import format_time
@@ -181,3 +182,32 @@ def write_callback(data):
181182
)
182183
assert archive_entry.uid == 1000
183184
assert archive_entry.gid == 1000
185+
186+
187+
def test_symlinks(tmpdir):
188+
os.chdir(tmpdir)
189+
with open('empty', 'w'):
190+
pass
191+
with open('unreadable', 'w') as f:
192+
f.write('secret')
193+
os.chmod('unreadable', 0)
194+
195+
os.symlink('empty', 'symlink-to-empty')
196+
os.symlink('unreadable', 'symlink-to-unreadable')
197+
198+
with libarchive.file_writer('archive.tar', 'gnutar') as archive:
199+
archive.add_files('symlink-to-empty', symlink_mode='hybrid')
200+
with pytest.raises(libarchive.ArchiveError):
201+
archive.add_files('symlink-to-unreadable', symlink_mode='logical')
202+
archive.add_files('symlink-to-unreadable', symlink_mode='physical')
203+
204+
with libarchive.file_reader('archive.tar') as archive:
205+
entries = iter(archive)
206+
e1 = next(entries)
207+
assert e1.pathname == 'symlink-to-empty'
208+
assert e1.isreg
209+
assert e1.size == 0
210+
e2 = next(entries)
211+
assert e2.pathname == 'symlink-to-unreadable'
212+
assert e2.issym
213+
assert e2.linkpath == 'unreadable'

0 commit comments

Comments
 (0)