简体   繁体   中英

python TarFile.extractall command deletes the files in the target directory

this is a simple piece of code in our production env. Python version 2.7

tar = tarfile.open(fileobj=pipe, mode='r|gz')
tar.extractall(d)

The finally blocks closes the tar file also.

   finally:
        if tar:
            tar.close()

However, on windows it is observed that some files in the target directory are deleted after the extractall(). Is this possible? has anyone seen such issue before?

Windows is windows 2016

In my experience tarfile.extractall() overwrites files and directories. If you edit some extracted files and than run again extractall(), you will obtain the "original" files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM