[utils/ldapcertfs] Ne pas écraser les fichiers déjà générés

This commit is contained in:
Valentin Samir 2014-10-26 01:29:50 +02:00
parent ff6a3f8e57
commit 38694d3662

View file

@ -192,7 +192,8 @@ class LdapCertFS(fuse.Fuse):
self.uid = 0 self.uid = 0
self.gid = 0 self.gid = 0
mpath = "/%s" % machine['host'][0] mpath = "/%s" % machine['host'][0]
self._storage[mpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid) if not mpath in self._storage:
self._storage[mpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid)
self._add_to_parent_dir(mpath) self._add_to_parent_dir(mpath)
def make_machine(self, hostname): def make_machine(self, hostname):
@ -201,8 +202,10 @@ class LdapCertFS(fuse.Fuse):
self._storage[mpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid) self._storage[mpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid)
for cert in machine.certificats(refresh=True): for cert in machine.certificats(refresh=True):
xpath = '%s/xid=%s' % (mpath, cert["xid"][0]) xpath = '%s/xid=%s' % (mpath, cert["xid"][0])
self._storage[xpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid) if not xpath in self._storage:
self._storage[xpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid)
self._add_to_parent_dir(xpath) self._add_to_parent_dir(xpath)
self._add_to_parent_dir(mpath)
def make_cert(self, xid): def make_cert(self, xid):
cert = self.search_cache(u"xid=%s" % xid)[0] cert = self.search_cache(u"xid=%s" % xid)[0]
@ -210,6 +213,7 @@ class LdapCertFS(fuse.Fuse):
self._storage[xpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid) self._storage[xpath]=Item(0755 | stat.S_IFDIR, self.uid, self.gid)
for file, file_data in self.files.items(): for file, file_data in self.files.items():
self.make_file(xid, file) self.make_file(xid, file)
self._add_to_parent_dir(xpath)
def make_file(self, xid, file): def make_file(self, xid, file):
cert = self.search_cache(u"xid=%s" % xid)[0] cert = self.search_cache(u"xid=%s" % xid)[0]
@ -400,7 +404,8 @@ class LdapCertFS(fuse.Fuse):
def _add_to_parent_dir(self, path): def _add_to_parent_dir(self, path):
parent_path = os.path.dirname(path) parent_path = os.path.dirname(path)
filename = os.path.basename(path) filename = os.path.basename(path)
self._storage[parent_path].data.add(filename) if parent_path in self._storage:
self._storage[parent_path].data.add(filename)
def _remove_from_parent_dir(self, path): def _remove_from_parent_dir(self, path):
parent_path = os.path.dirname(path) parent_path = os.path.dirname(path)