Index: applications/editors/josm/plugins/imagerycache/build.xml
===================================================================
--- applications/editors/josm/plugins/imagerycache/build.xml	(revision 29943)
+++ applications/editors/josm/plugins/imagerycache/build.xml	(revision 29944)
@@ -15,5 +15,5 @@
 
     <!-- enter the SVN commit message -->
-    <property name="commit.message" value="JOSM/ImageryCache: add optional imagerycache.randomAccessFile parameter for slower but less system-dependent storage"/>
+    <property name="commit.message" value="[JOSM_ImageryCache]: correct database cleaning, at last"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     <property name="plugin.main.version" value="5779"/>
Index: applications/editors/josm/plugins/imagerycache/nbproject/project.xml
===================================================================
--- applications/editors/josm/plugins/imagerycache/nbproject/project.xml	(revision 29943)
+++ applications/editors/josm/plugins/imagerycache/nbproject/project.xml	(revision 29944)
@@ -17,11 +17,7 @@
                 </source-folder>
                 <source-folder>
-                    <label>F:\Java\josm\core\src</label>
-                    <location>F:\Java\josm\core\src</location>
-                </source-folder>
-                <source-folder>
-                    <label>F:\Java\josm\core\src</label>
+                    <label>src</label>
                     <type>java</type>
-                    <location>F:\Java\josm\core\src</location>
+                    <location>src</location>
                     <encoding>UTF-8</encoding>
                 </source-folder>
@@ -48,6 +44,6 @@
                 <items>
                     <source-folder style="packages">
-                        <label>F:\Java\josm\core\src</label>
-                        <location>F:\Java\josm\core\src</location>
+                        <label>src</label>
+                        <location>src</location>
                     </source-folder>
                     <source-file>
@@ -67,5 +63,5 @@
         <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/3">
             <compilation-unit>
-                <package-root>F:\Java\josm\core\src</package-root>
+                <package-root>src</package-root>
                 <classpath mode="compile">../../core/src</classpath>
                 <source-level>1.6</source-level>
Index: applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java
===================================================================
--- applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java	(revision 29943)
+++ applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java	(revision 29944)
@@ -189,15 +189,22 @@
     public void cleanStorage(String name) {
         Main.info("Cleaning storage: {0}", name);
-        dbs.get(name).close();
-        for (int t=0; t<20; t++) {
-            try {
+        Main.info("There were {0} tiles in it", storages.get(name).size());
+        try {
+            dbs.get(name).close();
+            dbs.remove(name);
+            storages.remove(name);
+            for (int t=0; t<20; t++) {
                 String fname = getDBFileName(name, t);
                 File f = new File(cacheFolder, fname);
                 if (!f.exists() || !f.canWrite()) continue;
                 f.delete();
-            } catch (Exception e) {
-                Main.warn("Can not delete file");
+                f = new File(cacheFolder, fname+".p");
+                if (!f.exists() || !f.canWrite()) continue;
+                f.delete();
+                f = new File(cacheFolder, fname+".lock");
+                if (!f.exists() || !f.canWrite()) continue;
+                f.delete();
             }
-        }
+        } catch (Exception e) { Main.warn("Can not delete file, maybe it is locvked by another JOSM instance. This is not a serious error then."); }
     }
 }
