ampache / ampache-xbmc-plugin

KODI plugin for Ampache
Other
8 stars 3 forks source link

Adding a new ampache server overwrites the existing server #22

Closed cquike closed 2 years ago

cquike commented 2 years ago

I have an ampache server configured in the plugin. When I add a new server the old server disappears. This somehow worked at some point, so I think it happens under certain conditions:

  1. After a fresh installation of the plugin a new server is installed.
  2. A new server1 is added. This works fine
  3. The default server "apache" in 127.0.0.1 is removed
  4. A new server2 is added. This one overwrites server1 configuration
cquike commented 2 years ago

I seems to me that after removing the default server (which has key '0' in servers.json), the server1 with key '1' remains. The next server2 to be added will also be added as key '1', hence it overwrites existing configuration.

I think a possible solution could go along these lines:

--- a/resources/lib/servers_manager.py
+++ b/resources/lib/servers_manager.py
@@ -100,7 +100,7 @@ def addServer():
     xbmc.log("AmpachePlugin::addServer" , xbmc.LOGDEBUG )
     jsStorServer = json_storage.JsonStorage("servers.json")
     serverData = jsStorServer.getData()
-    stnum = str(len(list(serverData["servers"])))
+    stnum = str(max([int(i) for i in list(serverData["servers"])])+1)
     username = ""
     password = ""
     apikey = ""

I have quickly tried that and seems to work.

lusum commented 2 years ago

I have to test it, cause i have never found this bug. So, you add a new server1, delete the default server , add another one and the new server1 is overwritten.

cquike commented 2 years ago

Correct. I think with that sequence you should be able to reproduce the bug. I didn't actually need to add "correct" servers, i.e., it is enough to add enter dummy entries for the URL, etc... That's enough to reproduce the bug.

lusum commented 2 years ago

ok, i think i have never figured out such situation, so i need some time to manage a solution ( or simply try yours )

lusum commented 2 years ago

with 65e2d6b71041e739b54ca292c7a0e5ad8fff83f1 i have rewritten the delete server logic, based on your code as a starting point.

Now when we remove a server, we replace it with the latest in the list ( to avoid a mess in the long run ) and when you delete all the servers, the plugin don't crashes. I should have covered all the possibile options.

Can you test the code , so i can close this issue?

lusum commented 2 years ago

Issue closed, in case of other problems it will be reopened.