mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 08:39:15 +00:00
fix unique key for longkey (#100)
This commit is contained in:
@@ -548,8 +548,8 @@ class Cfg:
|
|||||||
dirs = list(map(self._norm_key_elem, dirs))
|
dirs = list(map(self._norm_key_elem, dirs))
|
||||||
return dirs
|
return dirs
|
||||||
|
|
||||||
def _get_long_key(self, path):
|
def _get_long_key(self, path, keys):
|
||||||
"""return a long key representing the
|
"""return a unique long key representing the
|
||||||
absolute path of path"""
|
absolute path of path"""
|
||||||
dirs = self._get_paths(path)
|
dirs = self._get_paths(path)
|
||||||
# prepend with indicator
|
# prepend with indicator
|
||||||
@@ -557,7 +557,7 @@ class Cfg:
|
|||||||
key = 'd_{}'.format('_'.join(dirs))
|
key = 'd_{}'.format('_'.join(dirs))
|
||||||
else:
|
else:
|
||||||
key = 'f_{}'.format('_'.join(dirs))
|
key = 'f_{}'.format('_'.join(dirs))
|
||||||
return key
|
return self._get_unique_key(key, keys)
|
||||||
|
|
||||||
def _get_short_key(self, path, keys):
|
def _get_short_key(self, path, keys):
|
||||||
"""return a unique key where path
|
"""return a unique key where path
|
||||||
@@ -574,14 +574,18 @@ class Cfg:
|
|||||||
key = '{}_{}'.format(pre, key)
|
key = '{}_{}'.format(pre, key)
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
return key
|
return key
|
||||||
okey = key
|
return self._get_unique_key(key, keys)
|
||||||
|
|
||||||
|
def _get_unique_key(self, key, keys):
|
||||||
|
"""return a unique dotfile key"""
|
||||||
|
newkey = key
|
||||||
cnt = 1
|
cnt = 1
|
||||||
while key in keys:
|
while newkey in keys:
|
||||||
# if unable to get a unique path
|
# if unable to get a unique path
|
||||||
# get a random one
|
# get a random one
|
||||||
key = '{}_{}'.format(okey, cnt)
|
newkey = '{}_{}'.format(key, cnt)
|
||||||
cnt += 1
|
cnt += 1
|
||||||
return key
|
return newkey
|
||||||
|
|
||||||
def _dotfile_exists(self, dotfile):
|
def _dotfile_exists(self, dotfile):
|
||||||
"""return True and the existing dotfile key
|
"""return True and the existing dotfile key
|
||||||
@@ -591,9 +595,10 @@ class Cfg:
|
|||||||
return True, [x[0] for x in dsts if x[1] == dotfile.dst][0]
|
return True, [x[0] for x in dsts if x[1] == dotfile.dst][0]
|
||||||
# return key for this new dotfile
|
# return key for this new dotfile
|
||||||
path = os.path.expanduser(dotfile.dst)
|
path = os.path.expanduser(dotfile.dst)
|
||||||
|
keys = self.dotfiles.keys()
|
||||||
if self.lnk_settings[self.key_long]:
|
if self.lnk_settings[self.key_long]:
|
||||||
return False, self._get_long_key(path)
|
return False, self._get_long_key(path, keys)
|
||||||
return False, self._get_short_key(path, self.dotfiles.keys())
|
return False, self._get_short_key(path, keys)
|
||||||
|
|
||||||
def new(self, dotfile, profile, link=LinkTypes.NOLINK, debug=False):
|
def new(self, dotfile, profile, link=LinkTypes.NOLINK, debug=False):
|
||||||
"""import new dotfile
|
"""import new dotfile
|
||||||
|
|||||||
Reference in New Issue
Block a user