On prend en compte la gnration concurrente de dn. Certes, c'est moche.
a vite d'utiliser des locks. darcs-hash:20060907220034-68412-bc06d68a2abdaaa5e31690f9a67d2c334e303807.gz
This commit is contained in:
parent
9ad806c9f3
commit
5087b93dbd
1 changed files with 35 additions and 23 deletions
|
@ -16,6 +16,7 @@ import ldap, ldap.modlist, ldap_passwd
|
||||||
import config, annuaires, iptools, chgpass, user_tests, cPickle, config_mail
|
import config, annuaires, iptools, chgpass, user_tests, cPickle, config_mail
|
||||||
from chgpass import chgpass
|
from chgpass import chgpass
|
||||||
from affich_tools import coul, prompt
|
from affich_tools import coul, prompt
|
||||||
|
from syslog import *
|
||||||
|
|
||||||
date_format = '%d/%m/%Y %H:%M'
|
date_format = '%d/%m/%Y %H:%M'
|
||||||
hostname = gethostname().split(".")[0]
|
hostname = gethostname().split(".")[0]
|
||||||
|
@ -1124,30 +1125,41 @@ class BaseClasseCrans(CransLdap):
|
||||||
|
|
||||||
if not self._init_data:
|
if not self._init_data:
|
||||||
### Nouvel enregistrement
|
### Nouvel enregistrement
|
||||||
# Génération du dn
|
# L'enregistrement peut échouer en cas de choix de dn concurrents
|
||||||
res = self.conn.search_s(self.base_dn, 2, self.filtre_idn)
|
# (il n'y a pas de lock sur les dn)
|
||||||
vidn = 1
|
for i in range(0, 5): # 5 tentatives
|
||||||
vidns = []
|
# Génération du dn
|
||||||
# Liste des dn pris
|
res = self.conn.search_s(self.base_dn, 2, self.filtre_idn)
|
||||||
for r in res:
|
vidn = 1
|
||||||
# r = ( dn, {} )
|
vidns = []
|
||||||
r = r[0].split(',')[0]
|
# Liste des dn pris
|
||||||
if r[:4] != '%s=' % self.idn: continue
|
for r in res:
|
||||||
vidns.append(int(r[4:]))
|
# r = ( dn, {} )
|
||||||
if self.idn=='fid':
|
r = r[0].split(',')[0]
|
||||||
# Pour une facture on prend un nouveau numéro
|
if r[:4] != '%s=' % self.idn: continue
|
||||||
vidn = max([0]+vidns)+1
|
vidns.append(int(r[4:]))
|
||||||
else:
|
if self.idn=='fid':
|
||||||
# Sinon on prend le premier libre
|
# Pour une facture on prend un nouveau numéro
|
||||||
while vidn in vidns:
|
vidn = max([0]+vidns)+1
|
||||||
vidn += 1
|
else:
|
||||||
|
# Sinon on prend le premier libre
|
||||||
|
while vidn in vidns:
|
||||||
|
vidn += 1
|
||||||
|
|
||||||
self.dn = '%s=%s,%s' % (self.idn, vidn, self.dn)
|
self.dn = '%s=%s,%s' % (self.idn, vidn, self.dn)
|
||||||
self._data[self.idn]= [ '%d' % vidn ]
|
self._data[self.idn]= [ '%d' % vidn ]
|
||||||
|
|
||||||
# Ecriture
|
try:
|
||||||
modlist = ldap.modlist.addModlist(self._data)
|
# Ecriture
|
||||||
self.conn.add_s(self.dn, modlist)
|
modlist = ldap.modlist.addModlist(self._data)
|
||||||
|
self.conn.add_s(self.dn, modlist)
|
||||||
|
break
|
||||||
|
except e:
|
||||||
|
# On logge
|
||||||
|
syslog("ldap_crans: exception: %s" % e)
|
||||||
|
if i == 4:
|
||||||
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
### Modification entrée
|
### Modification entrée
|
||||||
if not self._modifiable:
|
if not self._modifiable:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue