[Python-bugs-list] [ python-Bugs-412214 ] ZipFile constructor leaves files open

noreply@sourceforge.net noreply@sourceforge.net
Wed, 04 Apr 2001 11:04:37 -0700


Bugs item #412214, was updated on 2001-03-29 07:40
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=412214&group_id=5470

Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: Jens Quade (snejsource)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: ZipFile constructor leaves files open

Initial Comment:
During the construction of a ZipFile object, a 
file is opened and assigned to self.fp.

If anything goes wrong, i.e. the file is not a zipfile,
it is not closed explicitly.  

On Windows, this does not work:

import zipfile, os

filename="test.zip" # it's a broken one
try:
  zf=zipfile.ZipFile(filename)
  zf.close()
finally:
  os.unlink(zipfile)

=> OSError: [errno 13] Permission denied "test.zip"

(on Unix, the file stays open too, but unlink doesn't
fail)


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-03-29 23:27

Message:
Logged In: YES 
user_id=21627

Normally, the file should be closed when the last reference
to the zipfile is dropped. In this case, the traceback holds
onto the innermost frame (i.e. the one of __init__), which
holds onto self, which is the ZipFile. I agree this should
be fixed in __init__.

----------------------------------------------------------------------

Comment By: Jens Quade (snejsource)
Date: 2001-03-29 08:27

Message:
Logged In: YES 
user_id=137089

os.unlink(zipfile) should read os.unlink(filename). 

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=412214&group_id=5470