You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2009/08/22 15:33:28 UTC

svn commit: r806851 - /roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java

Author: snoopdave
Date: Sat Aug 22 13:33:28 2009
New Revision: 806851

URL: http://svn.apache.org/viewvc?rev=806851&view=rev
Log:
Making sure files don't get double imported in the case where a migration-status.properties is not found.

Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=806851&r1=806850&r2=806851&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java Sat Aug 22 13:33:28 2009
@@ -530,6 +530,8 @@
         }
 
         // loop through files and directories
+        int dirCount = 0;
+        int fileCount = 0;
         File[] files = oldDir.listFiles();
         for (int i=0; i<files.length; i++) {
 
@@ -549,6 +551,8 @@
                         roller.getMediaFileManager().createMediaFileDirectory(subDir);
                         roller.flush();
 
+                        dirCount++;
+
                     } catch (WebloggerException ex) {
                         log.error("ERROR creating directory: "
                             + newDir.getPath() + "/" + files[i].getName());
@@ -558,38 +562,52 @@
 
             } else { // a file: create a database record for it
 
-                log.debug("    Upgrade file: " + files[i].getAbsolutePath());
-                MediaFile mf = new MediaFile();
-                try {
-                    mf.setName(files[i].getName());
-                    mf.setDescription(files[i].getName());
-
-                    mf.setDateUploaded(new Timestamp(files[i].lastModified()));
-                    mf.setLastUpdated(new Timestamp(files[i].lastModified()));
-
-                    mf.setDirectory(newDir);
-                    mf.setCreatorUserName(user.getUserName());
-                    mf.setSharedForGallery(Boolean.FALSE);
-
-                    mf.setLength(files[i].length());
-                    mf.setInputStream(new FileInputStream(files[i]));
-                    mf.setContentType(Utilities.getContentTypeFromFileName(files[i].getName()));
-
-                    this.roller.getMediaFileManager().createMediaFile(weblog, mf);
-
-                } catch (WebloggerException ex) {
-                    log.error("ERROR writing file to new storage system: "
-                            + files[i].getAbsolutePath(), ex);
-                    
-                } catch (java.io.FileNotFoundException ex) {
-                    log.error("ERROR reading file from old storage system: "
-                            + files[i].getAbsolutePath(), ex);
+                // check to make sure that file does not already exist
+                if (newDir.hasMediaFile(files[i].getName())) {
+                    log.debug("    Skipping file that already exists: "
+                        + files[i].getName());
+                
+                } else {
+
+                    log.debug("    Upgrade file: " + files[i].getAbsolutePath());
+                    MediaFile mf = new MediaFile();
+                    try {
+                        mf.setName(files[i].getName());
+                        mf.setDescription(files[i].getName());
+
+                        mf.setDateUploaded(new Timestamp(files[i].lastModified()));
+                        mf.setLastUpdated(new Timestamp(files[i].lastModified()));
+
+                        mf.setDirectory(newDir);
+                        mf.setCreatorUserName(user.getUserName());
+                        mf.setSharedForGallery(Boolean.FALSE);
+
+                        mf.setLength(files[i].length());
+                        mf.setInputStream(new FileInputStream(files[i]));
+                        mf.setContentType(Utilities.getContentTypeFromFileName(files[i].getName()));
+
+                        this.roller.getMediaFileManager().createMediaFile(weblog, mf);
+
+                        fileCount++;
+
+                    } catch (WebloggerException ex) {
+                        log.error("ERROR writing file to new storage system: "
+                                + files[i].getAbsolutePath(), ex);
+
+                    } catch (java.io.FileNotFoundException ex) {
+                        log.error("ERROR reading file from old storage system: "
+                                + files[i].getAbsolutePath(), ex);
+                    }
                 }
             }
         }
 
         try { // flush changes to this directory
             roller.flush();
+
+            log.debug("Count of dirs  created: " + dirCount);
+            log.debug("Count of files created: " + fileCount);
+
         } catch (WebloggerException ex) {
             log.error("ERROR flushing changes to dir: " + newDir.getPath(), ex);
         }