File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -678,6 +678,33 @@ def exclude(name):
678678 finally :
679679 shutil .rmtree (tempdir )
680680
681+ def test_extractall_symlinks (self ):
682+ # Test if extractall works properly when tarfile contains symlinks
683+ tempdir = os .path .join (TEMPDIR , "testsymlinks" )
684+ temparchive = os .path .join (TEMPDIR , "testsymlinks.tar" )
685+ os .mkdir (tempdir )
686+ try :
687+ source_file = os .path .join (tempdir ,'source' )
688+ target_file = os .path .join (tempdir ,'symlink' )
689+ with open (source_file ,'w' ) as f :
690+ f .write ('something\n ' )
691+ os .symlink (source_file , target_file )
692+ tar = tarfile .open (temparchive ,'w' )
693+ tar .add (source_file )
694+ tar .add (target_file )
695+ tar .close ()
696+ # Let's extract it to the location which contains the symlink
697+ tar = tarfile .open (temparchive ,'r' )
698+ # this should not raise OSError: [Errno 17] File exists
699+ try :
700+ tar .extractall (path = tempdir )
701+ except OSError :
702+ self .fail ("extractall failed with symlinked files" )
703+ finally :
704+ tar .close ()
705+ finally :
706+ os .unlink (temparchive )
707+ shutil .rmtree (tempdir )
681708
682709class StreamWriteTest (WriteTestBase ):
683710
You can’t perform that action at this time.
0 commit comments