Project

General

Profile

« Previous | Next » 

Revision 2749

Added by Jing Tao over 18 years ago

Fixed bug that data file upload failed, record couldn't be deleted.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
2634 2634

  
2635 2635
        // Make sure we have a docid and datafile
2636 2636
        if (docid != null && fileList.containsKey("datafile")) {
2637

  
2637
            logMetacat.warn("Uploading data docid: " + docid);
2638 2638
            // Get a reference to the file part of the form
2639 2639
            FilePart filePart = (FilePart) fileList.get("datafile");
2640 2640
            String fileName = filePart.getFileName();
2641 2641
            logMetacat.warn("Uploading filename: " + fileName);
2642

  
2643 2642
            // Check if the right file existed in the uploaded data
2644 2643
            if (fileName != null) {
2645 2644

  
......
2648 2647
                    // +"...", 10);
2649 2648
                    //If document get lock data file grant
2650 2649
                    if (DocumentImpl.getDataFileLockGrant(docid)) {
2651
                        // register the file in the database (which generates
2652
                        // an exception
2653
                        //if the docid is not acceptable or other untoward
2654
                        // things happen
2655
                        DocumentImpl.registerDocument(fileName, "BIN", docid,
2656
                                username, groupnames);
2657

  
2658 2650
                        // Save the data file to disk using "docid" as the name
2659 2651
                        dataDirectory.mkdirs();
2660
                        File newFile = new File(dataDirectory, docid);
2661
                        long size = filePart.writeTo(newFile);
2652
                        File newFile = null;
2653
                        long size = 0;
2654
                        try
2655
                        {
2656
                          newFile = new File(dataDirectory, docid);
2657
                          size = filePart.writeTo(newFile);
2658
                        
2659
//                        register the file in the database (which generates
2660
                          // an exception
2661
                          //if the docid is not acceptable or other untoward
2662
                          // things happen
2663
                          DocumentImpl.registerDocument(fileName, "BIN", docid,
2664
                                username, groupnames);
2665
                        }
2666
                        catch (Exception ee)
2667
                        {
2668
                           //detelte the file to create
2669
                            newFile.delete();
2670
                            throw ee;
2671
                        }
2662 2672

  
2663 2673
                        EventLog.getInstance().log(request.getRemoteAddr(),
2664 2674
                                username, docid, "upload");
......
2682 2692
                    }
2683 2693

  
2684 2694
                } catch (Exception e) {
2695
                    
2685 2696
                    out.println("<?xml version=\"1.0\"?>");
2686 2697
                    out.println("<error>");
2687 2698
                    out.println(e.getMessage());

Also available in: Unified diff