From 867573de7145b7fa47afdb8981ffede9ea5ccb30 Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 27 Dec 2005 15:20:21 +0000 Subject: [PATCH] rebuildTags to rebuild the tags.db from the bookmarks.db git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1257 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/bookmarksDB.java | 55 ++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java index 7d6de7cf1..fa2e51281 100644 --- a/source/de/anomic/data/bookmarksDB.java +++ b/source/de/anomic/data/bookmarksDB.java @@ -56,31 +56,47 @@ import de.anomic.kelondro.kelondroDyn; import de.anomic.kelondro.kelondroException; import de.anomic.kelondro.kelondroMap; import de.anomic.plasma.plasmaURL; +import de.anomic.server.logging.serverLog; public class bookmarksDB { kelondroMap tagsTable; kelondroMap bookmarksTable; public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){ - if(bookmarksFile.exists() && tagsFile.exists()){ + //check if database exists + if(bookmarksFile.exists()){ try { + //open it this.bookmarksTable=new kelondroMap(new kelondroDyn(bookmarksFile, 1024*bufferkb)); - this.tagsTable=new kelondroMap(new kelondroDyn(tagsFile, 1024*bufferkb)); } catch (IOException e) { - //TODO: check if both are corrupted + //database reset :-(( bookmarksFile.delete(); bookmarksFile.getParentFile().mkdirs(); this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); + } + }else{ + //new database + bookmarksFile.getParentFile().mkdirs(); + this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); + } + //check if database exists + if(tagsFile.exists()){ + try { + //open it + this.tagsTable=new kelondroMap(new kelondroDyn(tagsFile, 1024*bufferkb)); + } catch (IOException e) { + //reset database tagsFile.delete(); tagsFile.getParentFile().mkdirs(); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); + rebuildTags(); } }else{ - bookmarksFile.getParentFile().mkdirs(); - this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); + //new database tagsFile.getParentFile().mkdirs(); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); + rebuildTags(); } } public void close(){ @@ -130,6 +146,27 @@ public class bookmarksDB { } return ret; } + public void rebuildTags(){ + serverLog.logInfo("BOOKMARKS", "rebuilding tags.db from bookmarks.db..."); + Iterator it=bookmarkIterator(true); + Bookmark bookmark; + Tag tag; + String[] tags; + while(it.hasNext()){ + bookmark=(Bookmark) it.next(); + tags = bookmark.getTags().split(","); + tag=null; + for(int i=0;i