Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-07-10 15:19:04 (GMT)
committer Sascha Silbe <sascha@silbe.org>2009-07-10 15:19:04 (GMT)
commitdbee334838fb7f4ec8d189fdf0b747170dcddcc0 (patch)
treeeeb21dd07eaf3996d138fbb17fe814da5aaf6729
parent1261585ed99d0d995ee0f9c568ef213c25526f8c (diff)
ensure tree_id, version_id, parent_id and ctime are all present in migrated datastores
-rw-r--r--src/carquinyol/migration.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
index 6502c2a..7cfa6e6 100644
--- a/src/carquinyol/migration.py
+++ b/src/carquinyol/migration.py
@@ -67,14 +67,17 @@ def _migrate_metadata_0(root_path, old_root_path, tree_id, version_id):
old_metadata_path = os.path.join(old_root_path, tree_id + '.metadata')
metadata = cjson.decode(open(old_metadata_path, 'r').read())
- if 'tree_id' not in metadata:
- metadata['tree_id'] = tree_id
-
+ metadata['tree_id'] = tree_id
metadata['version_id'] = version_id
+ metadata['parent_id'] = ''
if 'timestamp' not in metadata and 'mtime' in metadata:
- metadata['timestamp'] = \
+ metadata['ctime'] = \
time.mktime(time.strptime(metadata['mtime'], DATE_FORMAT))
+ elif 'timestamp' in metadata :
+ metadata['ctime'] = metadata.pop('timestamp')
+ else :
+ metadata['ctime'] = os.stat(old_metadata_path).st_ctime
for key, value in metadata.items():
try:
@@ -129,10 +132,20 @@ def migrate_from_1():
os.rename(os.path.join(root_path, hash02, tree_id),
new_path)
file(os.path.join(new_path, "metadata", "version_id"), "w").write(version_id)
+ file(os.path.join(new_path, "metadata", "parent_id"), "w").close()
uid_path = os.path.join(new_path, "metadata", "uid")
tid_path = os.path.join(new_path, "metadata", "tree_id")
+ timestamp_path = os.path.join(new_path, "metadata", "timestamp")
+ ctime_path = os.path.join(new_path, "metadata", "ctim")
if os.path.exists(uid_path) :
os.rename(uid_path, tid_path)
+ else :
+ file(tid_path, "w").write(tree_id)
+
+ if os.path.exists(timestamp_path) :
+ os.rename(timestamp_path, ctime_path)
+ else :
+ file(ctime_path, "w").write(str(os.stat(new_path).st_ctime))
except Exception:
logging.error('Error while migrating entry %r: %s\n' % \