Author: jflesch
Date: 2008-02-20 21:02:05 +0000 (Wed, 20 Feb 2008)
New Revision: 18088

Modified:
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
Log:
IndexBrowser : Fix a dead lock when adding a file to an index

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2008-02-20 18:48:04 UTC (rev 18087)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2008-02-20 21:02:05 UTC (rev 18088)
@@ -1352,22 +1352,25 @@
                int nextId;

                db = indexBrowser.getDb();
+               
+               Vector filesToManage = new Vector();

                synchronized(db.dbLock) {
                        try {
                                selectSt = 
db.getConnection().prepareStatement("SELECT id from files "+
-                                                                              
"WHERE indexParent = ? "+
-                                                                              
" AND LOWER(filename) LIKE ? "+
-                                                                              
"LIMIT 1");
+                                               "WHERE indexParent = ? "+
+                                               " AND LOWER(filename) LIKE ? "+
+                               "LIMIT 1");
                                st = 
db.getConnection().prepareStatement("INSERT INTO files "+
-                                                                        "(id, 
filename, publicKey, "+
-                                                                        " 
localPath, mime, size, "+
-                                                                        " 
category, indexParent, dontDelete) "+
-                                                                        
"VALUES (?, ?, ?, "+
-                                                                        " ?, 
?, ?, "+
-                                                                        " ?, 
?, TRUE)");
+                                               "(id, filename, publicKey, "+
+                                               " localPath, mime, size, "+
+                                               " category, indexParent, 
dontDelete) "+
+                                               "VALUES (?, ?, ?, "+
+                                               " ?, ?, ?, "+
+                               " ?, ?, TRUE)");
+
                                nextId = DatabaseManager.getNextId(db, "files");
-                               
+
                                if (nextId < 0) {
                                        selectSt.close();
                                        st.close();
@@ -1380,7 +1383,7 @@


                        for(final Iterator it = files.iterator();
-                           it.hasNext();) {
+                       it.hasNext();) {

                                final java.io.File ioFile = 
(java.io.File)it.next();

@@ -1408,13 +1411,9 @@
                                        st.execute();

                                        File file = new File(db, nextId);
+                                       
+                                       filesToManage.add(file);

-                                       if (insert) {
-                                               
file.insertOnFreenet(queueManager);
-                                       } else {
-                                               
file.recalculateCHK(queueManager);
-                                       }
-
                                        nextId++;
                                } catch(SQLException e) {
                                        Logger.error(new 
IndexManagementHelper(), "Error while adding file: "+e.toString());
@@ -1428,6 +1427,16 @@
                                /* \_o< */
                        }
                }
+               
+               for (Iterator it = filesToManage.iterator(); it.hasNext(); ){
+                       File f = (File)it.next();
+                       
+                       if (insert) {
+                               f.insertOnFreenet(queueManager);
+                       } else {
+                               f.recalculateCHK(queueManager);
+                       }                       
+               }

                indexBrowser.getTables().getFileTable().refresh();
        } /* addFiles() */


Reply via email to