sanity check so that nametrans does not lead to infinite folder creation

This commit is contained in:
Sebastian Spaeth 2011-09-19 14:01:48 +02:00
parent fd6261a50f
commit b92e453f0e

View File

@ -170,17 +170,25 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
# Find new folders on dst_repo. # Find new folders on dst_repo.
for dst_name, dst_folder in dst_hash.iteritems(): for dst_name, dst_folder in dst_hash.iteritems():
if dst_folder.sync_this and not dst_name in src_hash: if dst_folder.sync_this and not dst_name in src_hash:
# Check that back&forth nametrans lead to identical names # nametrans sanity check!
# Does nametrans back&forth lead to identical names?
#src_name is the unmodified full src_name #src_name is the unmodified full src_name
newsrc_name = dst_name.replace(dst_repo.getsep(), newsrc_name = dst_name.replace(dst_repo.getsep(),
src_repo.getsep()) src_repo.getsep())
folder = self.getfolder(newsrc_name) folder = self.getfolder(newsrc_name)
newdst_name = folder.getvisiblename().replace( newdst_name = folder.getvisiblename().replace(
src_repo.getsep(), dst_repo.getsep()) src_repo.getsep(), dst_repo.getsep())
if newsrc_name == newdst_name: if newsrc_name != newdst_name:
assert False, "newdstname %s equals newsrcname %s %s %s" % (newdst_name, newsrc_name, dst_name, folder) raise OfflineImapError("INFINITE FOLDER CREATION DETECTED! "
else: "Folder '%s' (repository '%s') would be created as fold"
assert False, "newdstname %s Does not equal newsrcname %s %s %s" % (newdst_name, newsrc_name, dst_name, folder) "er '%s' (repository '%s'). The atter becomes '%s' in r"
"eturn, leading to infinite folder creation cycles.\n S"
"OLUTION: 1) Do set your nametrans rules on both reposi"
"tories so they lead to identical names if applied back"
" and forth. 2) Use folderfilter settings on a reposito"
"ry to prevent some folders from being created on the o" "ther side." % (dst_folder, dst_repo, newsrc_name,
src_repo, newdst_name),
OfflineImapError.ERROR.REPO)
# end sanity check, actually create the folder # end sanity check, actually create the folder
try: try: