Make library_ids stable as long as the library folder names are unique

This commit is contained in:
Kovid Goyal 2015-06-16 19:24:58 +05:30
parent 794ebd0075
commit e200792884

View File

@ -7,6 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import os
from binascii import hexlify
from collections import OrderedDict
from importlib import import_module
from threading import Lock
@ -33,7 +34,11 @@ class LibraryBroker(object):
seen.add(path)
if not LibraryDatabase.exists_at(path):
continue
library_id = 'lib%d' % len(self.lmap)
bname = library_id = hexlify(os.path.basename(path).encode('utf-8')).decode('ascii')
c = 0
while library_id in self.lmap:
c += 1
library_id = bname + '%d' % c
if i == 0:
self.default_library = library_id
self.lmap[library_id] = path