Changeset 6514


Ignore:
Timestamp:
Aug 13, 2014, 2:22:46 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1831: Packed file exporter doesn't close stream after an exception

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/src/plugins/core/net/sf/basedb/plugins/PackedFileExporter.java

    r6512 r6514  
    5656import net.sf.basedb.core.signal.SignalTarget;
    5757import net.sf.basedb.core.signal.ThreadSignalHandler;
     58import net.sf.basedb.util.FileUtil;
    5859import net.sf.basedb.util.Values;
    5960import net.sf.basedb.util.zip.FilePacker;
     
    385386      long size = 0;
    386387      InputStream in = null;
    387       if (item.getType() == Item.FILE)
    388       {
    389         File f = (File)item;
    390         entryPath = f.getPath().toString();
    391         lastModified = f.getLastUpdate();
    392         in = f.getDownloadStream(0);
    393         size = f.getSize();
    394         if (removeItems && f.hasPermission(Permission.DELETE)) f.setRemoved(true);
    395       }
    396       else
    397       {
    398         Directory d = (Directory)item;
    399         entryPath = d.getPath().toString();
    400         if (removeItems && d.hasPermission(Permission.DELETE)) d.setRemoved(true);
    401       }
    402      
    403       // Remove rootPath from entryPath
    404       entryPath = entryPath.substring(rootPath.length());
    405      
    406       // Update progress
    407       if (progress != null)
    408       {
    409         int percent = (int)(completedBytes * progressFactor);
    410         progress.display(percent, "Compressing '" + entryPath + "'; " +
    411           currentFile + " of " + numFiles + " file(s) (" +
    412           Values.formatBytes(completedBytes) + " of " + Values.formatBytes(totalBytes) + ")");
    413       }
    414 
    415       // Send to FilePacker
    416       packer.pack(entryPath, in, size, lastModified == null ? 0 : lastModified.getTime());
    417       if (in != null) in.close();
    418       completedBytes += size;
     388      try
     389      {
     390        if (item.getType() == Item.FILE)
     391        {
     392          File f = (File)item;
     393          entryPath = f.getPath().toString();
     394          lastModified = f.getLastUpdate();
     395          in = f.getDownloadStream(0);
     396          size = f.getSize();
     397          if (removeItems && f.hasPermission(Permission.DELETE)) f.setRemoved(true);
     398        }
     399        else
     400        {
     401          Directory d = (Directory)item;
     402          entryPath = d.getPath().toString();
     403          if (removeItems && d.hasPermission(Permission.DELETE)) d.setRemoved(true);
     404        }
     405       
     406        // Remove rootPath from entryPath
     407        entryPath = entryPath.substring(rootPath.length());
     408       
     409        // Update progress
     410        if (progress != null)
     411        {
     412          int percent = (int)(completedBytes * progressFactor);
     413          progress.display(percent, "Compressing '" + entryPath + "'; " +
     414            currentFile + " of " + numFiles + " file(s) (" +
     415            Values.formatBytes(completedBytes) + " of " + Values.formatBytes(totalBytes) + ")");
     416        }
     417 
     418        // Send to FilePacker
     419        packer.pack(entryPath, in, size, lastModified == null ? 0 : lastModified.getTime());
     420        completedBytes += size;
     421      }
     422      finally
     423      {
     424        FileUtil.close(in);
     425      }
    419426    }
    420427   
Note: See TracChangeset for help on using the changeset viewer.