Fix broken init_git_dir logic 🐛

This commit is contained in:
Kristóf Tóth 2018-08-06 13:40:16 +02:00
parent b140550686
commit 782df25bee

View File

@ -4,8 +4,6 @@
from os.path import join as joinpath from os.path import join as joinpath
from os.path import basename from os.path import basename
from os import makedirs from os import makedirs
from uuid import uuid4
from glob import glob
from dateutil import parser as dateparser from dateutil import parser as dateparser
@ -29,19 +27,16 @@ class DirectorySnapshottingEventHandler(EventHandlerBase):
} }
def init_snapshot_providers(self, directories): def init_snapshot_providers(self, directories):
for directory in directories: for index, directory in enumerate(directories):
git_dir = self.init_git_dir(directory) git_dir = self.init_git_dir(index, directory)
self.snapshot_providers[directory] = SnapshotProvider(directory, git_dir) self.snapshot_providers[directory] = SnapshotProvider(directory, git_dir)
@staticmethod @staticmethod
def init_git_dir(directory): def init_git_dir(index, directory):
git_dir_prefix = joinpath( git_dir = joinpath(
TFWENV.SNAPSHOTS_DIR, TFWENV.SNAPSHOTS_DIR,
f'{basename(directory)}-' f'{basename(directory)}-{index}'
) )
potential_dirs = glob(f'{git_dir_prefix}*')
git_dir = potential_dirs[0] if potential_dirs else f'{git_dir_prefix}{str(uuid4())}'
makedirs(git_dir, exist_ok=True) makedirs(git_dir, exist_ok=True)
return git_dir return git_dir