Forráskód Böngészése

HUE-2383 [filebrowser] Close file handle in read_contents properly

Ivan Orlov 11 éve
szülő
commit
a0e98774df
1 módosított fájl, 3 hozzáadás és 1 törlés
  1. 3 1
      apps/filebrowser/src/filebrowser/views.py

+ 3 - 1
apps/filebrowser/src/filebrowser/views.py

@@ -621,6 +621,7 @@ def read_contents(codec_type, path, fs, offset, length):
        Returns: A tuple of codec_type, offset, length and contents read.
        Returns: A tuple of codec_type, offset, length and contents read.
     """
     """
     contents = ''
     contents = ''
+    fhandle = None
 
 
     try:
     try:
         fhandle = fs.open(path)
         fhandle = fs.open(path)
@@ -660,7 +661,8 @@ def read_contents(codec_type, path, fs, offset, length):
             contents = _read_simple(fhandle, path, offset, length, stats)
             contents = _read_simple(fhandle, path, offset, length, stats)
 
 
     finally:
     finally:
-        fhandle.close()
+        if fhandle:
+            fhandle.close()
 
 
     return (codec_type, offset, length, contents)
     return (codec_type, offset, length, contents)