classification
Title: tarfile: OSError with TarFile.add(..., recursive=True) about non-existing file
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: denis, lars.gustaebel, sandro.tosi
Priority: normal Keywords:

Created on 2009-10-10 23:49 by denis, last changed 2011-04-05 16:25 by lars.gustaebel.

Files
File name Uploaded Description Edit
backup2.py denis, 2009-10-10 23:49 backup script
Messages (3)
msg93845 - (view) Author: Denis Martinez (denis) Date: 2009-10-10 23:49
I have written a server backup script (file attached) which archives a
list of directories with tarfile and uploads the file to FTP. Today, the
script hanged, with an exception:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
    self.run()
  File "./backup.py", line 48, in run
    tar.add(file_or_directory, recursive=True)
  File "/usr/lib/python2.6/tarfile.py", line 1981, in add
    self.add(os.path.join(name, f), os.path.join(arcname, f), recursive,
exclude)
  File "/usr/lib/python2.6/tarfile.py", line 1965, in add
    tarinfo = self.gettarinfo(name, arcname)
  File "/usr/lib/python2.6/tarfile.py", line 1834, in gettarinfo
    statres = os.lstat(name)
OSError: [Errno 2] No such file or directory: '/srv/myfile.htdigest'

What I did here is that I removed the htdigest file while the tarfile
was archiving /srv. I haven't managed to reproduce the bug a second time.
It seems normal that tarfile shouldn't fail is this case; maybe it needs
some exception checking around the stat/lstat calls.
msg132526 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2011-03-29 20:56
Hi,
I don't understand why you think tarfile should not fail in case you're trying to add a non-existing file. the problem is that glob() already extracted a list of files&dirs and then while the script is tar-ring them, you're removing some of them -> script crash.

if you want to do it, then wrap tar.add() in a try..catch construct, but I think the behavior of tar.add() is correct here.

Lars, you assigned this issue to yourself: what do you think it's the best action now (i was about to close it :) ?
msg133048 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2011-04-05 16:25
I kept this issue open, because I have not yet come to a decision. I don't think the current behaviour is a bug, but these kinds of errors could be handled more intelligently.
For example, errors during extraction can be hidden depending on the TarFile.errorlevel attribute. Something similar could be done for creation of archives. What exactly, I don't know... I have not yet managed to make up my mind.
History
Date User Action Args
2011-04-05 16:25:08lars.gustaebelsetmessages: + msg133048
2011-03-29 20:56:33sandro.tosisetnosy: + sandro.tosi
messages: + msg132526
2010-07-11 09:54:13BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-10-13 14:30:01lars.gustaebelsetassignee: lars.gustaebel

nosy: + lars.gustaebel
2009-10-10 23:49:21deniscreate