Project

General

Profile

« Previous | Next » 

Revision 3161

As a fix to http://bugzilla.ecoinformatics.org/show_bug.cgi?id=2748, I'm applying
the patch sent to me from Mike Frenock when he reported this bug.

This patch changes MetaCatServlet.handleUploadAction() by first setting
a boolean flag on whether the file to be uploaded exists already. If it
doesn't exist, the transaction continues, uploading and registering the
data file. In the event of an Exception during the registration, the file
will be deleted, since the file's existence is not recorded in the database.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
2918 2918
                        dataDirectory.mkdirs();
2919 2919
                        File newFile = null;
2920 2920
                        long size = 0;
2921
                        boolean fileExists = false;
2921 2922
                        try
2922 2923
                        {
2923 2924
                          newFile = new File(dataDirectory, docid);
2924
                          size = filePart.writeTo(newFile);
2925
                          fileExists = newFile.exists();
2926
                          if ( fileExists == false ) {
2927
                            size = filePart.writeTo(newFile); 
2928
                          }
2925 2929
                        
2926 2930
//                        register the file in the database (which generates
2927 2931
                          // an exception
......
2932 2936
                        }
2933 2937
                        catch (Exception ee)
2934 2938
                        {
2935
                           //detelte the file to create
2936
                            newFile.delete();
2939
                           //delete the file to create
2940
                           // if the revision already exists, don't delete 
2941
                           // the file
2942
                            if ( fileExists == false ) {
2943
                              newFile.delete();
2944
                            }
2945
                            
2937 2946
                            throw ee;
2938 2947
                        }
2939 2948

  

Also available in: Unified diff