1. Marcin Kuzminski
  2. RhodeCode

Issues

Issue #455 resolved

Creating an archive generates an exception on Windows

Eric Blood
created an issue

When creating an archive on a Windows server an exception is generated when it tries to remove the temporary file (the archive is still downloaded but the exception is emailed as an error):

{{{ URL: http://.../hpcc/archive/tip.zip Module weberror.errormiddleware:242 in next << raise StopIteration try: return self.app_iterator.next() except StopIteration: self.closed = True

return self.app_iterator.next() Module rhodecode.controllers.files:384 in get_chunked_archive << data = stream.read(4096) if not data: os.remove(archive) break yield data os.remove(archive) WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\users\admini~1\appdata\local\temp\2\tmpvomxre' }}}

It looks like this happens because mkstemp returns an open file handle that is never closed and on Windows you can't delete an open file.

With the following code at the end of archivefile (in files.py) the exception was eliminated:

{{{ import tempfile archivehandle, archive = tempfile.mkstemp() t = open(archive, 'wb') cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos) t.close()

    def get_chunked_archive(archive):
        stream = open(archive, 'rb')
        while True:
            data = stream.read(4096)
            if not data:
                stream.close()                    
                os.close(archivehandle)
                os.remove(archive)
                break
            yield data

}}}

Comments (1)

  1. Marcin Kuzminski repo owner

    Thanks a lot for pointing to this issue, and proposing a solution. I made a lot of changes recently to this in beta branch for serving the archive files, but reverted to your proposed solution, it seams it works the best for now.

  2. Log in to comment