diff options
author | Jan Cholasta <jcholast@redhat.com> | 2013-12-10 11:53:32 +0100 |
---|---|---|
committer | Petr Viktorin <pviktori@redhat.com> | 2014-01-10 14:41:39 +0100 |
commit | d6c3d3f57afb82f39c400e98b878fb57e00c1139 (patch) | |
tree | 081c633f594fd0acaa2543c0fe09532494ce3f1f | |
parent | 4284a8349b4db3de2d67be6c201cd2490ad48a20 (diff) | |
download | freeipa-d6c3d3f57afb82f39c400e98b878fb57e00c1139.tar.gz freeipa-d6c3d3f57afb82f39c400e98b878fb57e00c1139.tar.xz freeipa-d6c3d3f57afb82f39c400e98b878fb57e00c1139.zip |
Store old entry state in dict rather than LDAPEntry.
https://fedorahosted.org/freeipa/ticket/3488
-rw-r--r-- | ipapython/ipaldap.py | 46 | ||||
-rw-r--r-- | ipaserver/plugins/ldap2.py | 4 |
2 files changed, 19 insertions, 31 deletions
diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index de38db5d7..cebf86957 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -690,14 +690,14 @@ class LDAPEntry(collections.MutableMapping): self._raw = {} self._sync = {} self._not_list = set() - self._orig = self + self._orig = {} self._raw_view = None self._single_value_view = None if isinstance(_obj, LDAPEntry): #pylint: disable=E1103 self._not_list = set(_obj._not_list) - self._orig = _obj._orig + self._orig = dict(_obj._orig) if _obj.conn is _conn: self._names = CIDict(_obj._names) self._nice = dict(_obj._nice) @@ -743,31 +743,6 @@ class LDAPEntry(collections.MutableMapping): def copy(self): return LDAPEntry(self) - def clone(self): - result = LDAPEntry(self._conn, self._dn) - - result._names = deepcopy(self._names) - result._nice = deepcopy(self._nice) - result._raw = deepcopy(self._raw) - result._sync = deepcopy(self._sync) - result._not_list = deepcopy(self._not_list) - if self._orig is not self: - result._orig = self._orig.clone() - - return result - - def reset_modlist(self, other=None): - """ - Make the current state of the entry a new reference point for change - tracking. - """ - if other is None: - other = self - assert isinstance(other, LDAPEntry) - if other is self: - self._orig = self - self._orig = other.clone() - def _sync_attr(self, name): nice = self._nice[name] assert isinstance(nice, list) @@ -840,6 +815,8 @@ class LDAPEntry(collections.MutableMapping): if oldname in self._not_list: self._not_list.remove(oldname) self._not_list.add(name) + if oldname in self._orig: + self._orig[name] = self._orig.pop(oldname) else: if self._conn.schema is not None: attrtype = self._conn.schema.get_obj(ldap.schema.AttributeType, @@ -851,6 +828,11 @@ class LDAPEntry(collections.MutableMapping): self._names[name] = name + for oldname in self._orig.keys(): + if self._names.get(oldname) == name: + self._orig[name] = self._orig.pop(oldname) + break + def _set_nice(self, name, value): name = self._attr_name(name) self._add_attr_name(name) @@ -981,14 +963,20 @@ class LDAPEntry(collections.MutableMapping): return NotImplemented return other is not self + def reset_modlist(self, other=None): + if other is None: + other = self + assert isinstance(other, LDAPEntry) + self._orig = deepcopy(dict(other.raw)) + def generate_modlist(self): modlist = [] names = set(self.iterkeys()) - names.update(self._orig.iterkeys()) + names.update(self._orig) for name in names: new = self.raw.get(name) - old = self._orig.raw.get(name) + old = self._orig.get(name) if old and not new: modlist.append((ldap.MOD_DELETE, name, None)) continue diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 97f26ec77..f6284dcb2 100644 --- a/ipaserver/plugins/ldap2.py +++ b/ipaserver/plugins/ldap2.py @@ -272,7 +272,7 @@ class ldap2(LDAPClient, CrudBackend): try: config_entry = getattr(context, 'config_entry') if config_entry.conn is self.conn: - return config_entry.clone() + return config_entry except AttributeError: # Not in our context yet pass @@ -289,7 +289,7 @@ class ldap2(LDAPClient, CrudBackend): for a in self.config_defaults: if a not in config_entry: config_entry[a] = self.config_defaults[a] - context.config_entry = config_entry.clone() + context.config_entry = config_entry return config_entry def has_upg(self): |