Dirk Stöcker schrieb:
> On Mon, 25 Aug 2008, Robin Rattay wrote:
>> Has this actually worked at all or only on specific environments? It
>> seems that the update mechanism needs to be changed.
> 
> Works on Linux, but probably you're right and it wont work on Windows due 
> to the strange Windows file locking. Anyway I seldom use Windows, so 
> that's not my problem :-)
> 
> Maybe a solution would be to store files with an intermediate name in 
> case of copy failure and copy these on restart before plugins get loaded.

Here you go...

Robin
Index: src/org/openstreetmap/josm/plugins/PluginDownloader.java
===================================================================
--- src/org/openstreetmap/josm/plugins/PluginDownloader.java    (revision 868)
+++ src/org/openstreetmap/josm/plugins/PluginDownloader.java    (working copy)
@@ -53,12 +53,14 @@
                }
 
                @Override protected void realRun() throws SAXException, 
IOException {
+                       File updatedPluginDir = new 
File(Main.pref.getPreferencesDir() + "plugin-updates");
+                       if (!updatedPluginDir.exists())
+                               updatedPluginDir.mkdirs();
                        for (PluginDescription d : toUpdate) {
-                               File tempFile = new 
File(Main.pref.getPreferencesDir()+"temp.jar");
-                               if (download(d.resource, tempFile)) {
-                                       tempFile.renameTo(new 
File(Main.pref.getPreferencesDir()+"plugins/"+d.name+".jar"));
+                               File pluginFile = new File(updatedPluginDir, 
d.name + ".jar");
+                               if (download(d.resource, pluginFile))
                                        count++;
-                               } else
+                               else
                                        errors += d.name + "\n";
                        }
                }
Index: src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- src/org/openstreetmap/josm/gui/MainApplication.java (revision 868)
+++ src/org/openstreetmap/josm/gui/MainApplication.java (working copy)
@@ -118,6 +118,17 @@
                        Main.pref.save();
                }
 
+               // Copy updated plugins to proper directory
+               File updatedPluginDir = new File(Main.pref.getPreferencesDir() 
+ "plugin-updates/");
+               File pluginDir = new File(Main.pref.getPreferencesDir() + 
"plugins/");
+               if (updatedPluginDir.exists() && 
updatedPluginDir.isDirectory()) {
+                       for (File updatedPlugin : updatedPluginDir.listFiles()) 
{
+                               File plugin = new File(pluginDir, 
updatedPlugin.getName());
+                               plugin.delete();
+                               updatedPlugin.renameTo(plugin);
+                       }
+               }
+
                // load the early plugins
                Main.loadPlugins(true);
 

_______________________________________________
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev

Reply via email to