[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat MetaCatServlet.java

Jing Tao tao at ecoinformatics.org
Wed Nov 16 12:38:42 PST 2005


tao         05/11/16 12:38:42

  Modified:    src/edu/ucsb/nceas/metacat MetaCatServlet.java
  Log:
  Fixed bug that data file upload failed, record couldn't be deleted.
  
  Revision  Changes    Path
  1.235     +24 -13    metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java
  
  Index: MetaCatServlet.java
  ===================================================================
  RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java,v
  retrieving revision 1.234
  retrieving revision 1.235
  diff -u -r1.234 -r1.235
  --- MetaCatServlet.java	10 Nov 2005 21:34:44 -0000	1.234
  +++ MetaCatServlet.java	16 Nov 2005 20:38:41 -0000	1.235
  @@ -6,9 +6,9 @@
    *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley
    *    Release: @release@
    *
  - *   '$Author: sgarg $'
  - *     '$Date: 2005/11/10 21:34:44 $'
  - * '$Revision: 1.234 $'
  + *   '$Author: tao $'
  + *     '$Date: 2005/11/16 20:38:41 $'
  + * '$Revision: 1.235 $'
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
  @@ -2634,12 +2634,11 @@
   
           // Make sure we have a docid and datafile
           if (docid != null && fileList.containsKey("datafile")) {
  -
  +            logMetacat.warn("Uploading data docid: " + docid);
               // Get a reference to the file part of the form
               FilePart filePart = (FilePart) fileList.get("datafile");
               String fileName = filePart.getFileName();
               logMetacat.warn("Uploading filename: " + fileName);
  -
               // Check if the right file existed in the uploaded data
               if (fileName != null) {
   
  @@ -2648,17 +2647,28 @@
                       // +"...", 10);
                       //If document get lock data file grant
                       if (DocumentImpl.getDataFileLockGrant(docid)) {
  -                        // register the file in the database (which generates
  -                        // an exception
  -                        //if the docid is not acceptable or other untoward
  -                        // things happen
  -                        DocumentImpl.registerDocument(fileName, "BIN", docid,
  -                                username, groupnames);
  -
                           // Save the data file to disk using "docid" as the name
                           dataDirectory.mkdirs();
  -                        File newFile = new File(dataDirectory, docid);
  -                        long size = filePart.writeTo(newFile);
  +                        File newFile = null;
  +                        long size = 0;
  +                        try
  +                        {
  +                          newFile = new File(dataDirectory, docid);
  +                          size = filePart.writeTo(newFile);
  +                        
  +//                        register the file in the database (which generates
  +                          // an exception
  +                          //if the docid is not acceptable or other untoward
  +                          // things happen
  +                          DocumentImpl.registerDocument(fileName, "BIN", docid,
  +                                username, groupnames);
  +                        }
  +                        catch (Exception ee)
  +                        {
  +                           //detelte the file to create
  +                            newFile.delete();
  +                            throw ee;
  +                        }
   
                           EventLog.getInstance().log(request.getRemoteAddr(),
                                   username, docid, "upload");
  @@ -2682,6 +2692,7 @@
                       }
   
                   } catch (Exception e) {
  +                    
                       out.println("<?xml version=\"1.0\"?>");
                       out.println("<error>");
                       out.println(e.getMessage());
  
  
  


More information about the Metacat-cvs mailing list