From ef014a5df357d312fa7878997dafe499ace551e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Thu, 5 Feb 2009 12:47:04 +0000
Subject: [PATCH]  - disallow to do more than one migration, support concurrent
 case of migration invocation

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25458 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Core/Folder.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/product/ERP5Type/Core/Folder.py b/product/ERP5Type/Core/Folder.py
index 07691399a4..f3644af51a 100644
--- a/product/ERP5Type/Core/Folder.py
+++ b/product/ERP5Type/Core/Folder.py
@@ -78,6 +78,9 @@ import os
 from zLOG import LOG, PROBLEM, WARNING
 import warnings
 
+# variable to inform about migration process
+migration_process_lock = "_migration_in_progress"
+
 REINDEX_SPLIT_COUNT = 100 # if folder containes more than this, reindexing should be splitted.
 from Products.ERP5Type.Message import translateString
 
@@ -441,6 +444,17 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
     Then it will migrate foder from btree to hbtree.
     """    
     BUNDLE_COUNT = 10
+
+    # if folder is already migrated or migration process is in progress
+    # do not do anything beside logging    
+    if getattr(self, migration_process_lock, None) is not None \
+       or self.isHBTree():
+      LOG('migrateToHBTree', WARNING,
+        'Folder %s already migrated'%(self.getPath(),))
+      return
+    # lock folder migration early
+    setattr(self, migration_process_lock, 1)
+    
     # we may want to change all objects ids before migrating to new folder type
     # set new id generator here so that object created while migration
     # got a right id
@@ -479,7 +493,9 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
     and migration
     """
     if getattr(self, "_tree", None) is not None:
-      delattr(self, "_tree")
+      delattr(self, "_tree")    
+    if getattr(self, migration_process_lock, None) is not None:
+      delattr(self, migration_process_lock)
 
   def _launchCopyObjectToHBTree(self, tag):
     """
-- 
2.30.9