Changeset - 5260517c2802
[Not reviewed]
stable
0 1 0
Mads Kiilerich - 10 years ago 2015-06-09 22:12:21
madski@unity3d.com
archive: fix archive failing first time on Windows - close file descriptor early

File descriptors is not used correctly - this is just a minimal stop gap.
1 file changed with 2 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/files.py
Show inline comments
 
@@ -556,7 +556,7 @@ class FilesController(BaseRepoController
 
            cached_archive_path = os.path.join(CONFIG['archive_cache_dir'], archive_name)
 
            if os.path.isfile(cached_archive_path):
 
                log.debug('Found cached archive in %s' % cached_archive_path)
 
                fd, archive = None, cached_archive_path
 
                archive = cached_archive_path
 
                use_cached_archive = True
 
            else:
 
                log.debug('Archive %s is not yet cached' % (archive_name))
 
@@ -564,6 +564,7 @@ class FilesController(BaseRepoController
 
        if not use_cached_archive:
 
            # generate new archive
 
            fd, archive = tempfile.mkstemp()
 
            os.close(fd)
 
            temp_stream = open(archive, 'wb')
 
            log.debug('Creating new temp archive in %s' % archive)
 
            cs.fill_archive(stream=temp_stream, kind=fileformat, subrepos=subrepos)
 
@@ -580,8 +581,6 @@ class FilesController(BaseRepoController
 
                data = stream.read(16 * 1024)
 
                if not data:
 
                    stream.close()
 
                    if fd:  # fd means we used temporary file
 
                        os.close(fd)
 
                    if not archive_cache_enabled:
 
                        log.debug('Destroying temp archive %s' % archive)
 
                        os.remove(archive)
0 comments (0 inline, 0 general)