@@ -948,6 +948,20 @@ def test_tar_with_empty_directory(self):
948
948
tar_data = tarfile .open (fileobj = archive )
949
949
self .assertEqual (sorted (tar_data .getnames ()), ['bar' , 'foo' ])
950
950
951
+ @pytest .mark .skipif (IS_WINDOWS_PLATFORM , reason = 'No chmod on Windows' )
952
+ def test_tar_with_inaccessible_file (self ):
953
+ base = tempfile .mkdtemp ()
954
+ full_path = os .path .join (base , 'foo' )
955
+ self .addCleanup (shutil .rmtree , base )
956
+ with open (full_path , 'w' ) as f :
957
+ f .write ('content' )
958
+ os .chmod (full_path , 0o222 )
959
+ with pytest .raises (IOError ) as ei :
960
+ tar (base )
961
+
962
+ assert 'Can not access file in context: {}' .format (full_path ) in \
963
+ ei .exconly ()
964
+
951
965
@pytest .mark .skipif (IS_WINDOWS_PLATFORM , reason = 'No symlinks on Windows' )
952
966
def test_tar_with_file_symlinks (self ):
953
967
base = tempfile .mkdtemp ()
@@ -975,6 +989,18 @@ def test_tar_with_directory_symlinks(self):
975
989
sorted (tar_data .getnames ()), ['bar' , 'bar/foo' , 'foo' ]
976
990
)
977
991
992
+ @pytest .mark .skipif (IS_WINDOWS_PLATFORM , reason = 'No symlinks on Windows' )
993
+ def test_tar_with_broken_symlinks (self ):
994
+ base = tempfile .mkdtemp ()
995
+ self .addCleanup (shutil .rmtree , base )
996
+ for d in ['foo' , 'bar' ]:
997
+ os .makedirs (os .path .join (base , d ))
998
+
999
+ os .symlink ('../baz' , os .path .join (base , 'bar/foo' ))
1000
+ with tar (base ) as archive :
1001
+ tar_data = tarfile .open (fileobj = archive )
1002
+ assert sorted (tar_data .getnames ()) == ['bar' , 'bar/foo' , 'foo' ]
1003
+
978
1004
@pytest .mark .skipif (IS_WINDOWS_PLATFORM , reason = 'No UNIX sockets on Win32' )
979
1005
def test_tar_socket_file (self ):
980
1006
base = tempfile .mkdtemp ()
0 commit comments