[Sugar-devel] [PATCH v1 2/5] Add migration code from DS v0 for the filesize property

Andrés Ambrois andresambrois at gmail.com
Sun May 23 08:04:08 EDT 2010


Signed-off-by: Andrés Ambrois <andresambrois at gmail.com>
---
 src/carquinyol/migration.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
index 95ee391..228467c 100644
--- a/src/carquinyol/migration.py
+++ b/src/carquinyol/migration.py
@@ -45,8 +45,8 @@ def migrate_from_0():
 
         logging.debug('Migrating entry %r', uid)
         try:
-            _migrate_metadata(root_path, old_root_path, uid)
             _migrate_file(root_path, old_root_path, uid)
+            _migrate_metadata(root_path, old_root_path, uid)
             _migrate_preview(root_path, old_root_path, uid)
         except Exception:
             logging.exception('Error while migrating entry %r', uid)
@@ -73,6 +73,13 @@ def _migrate_metadata(root_path, old_root_path, uid):
         metadata['timestamp'] = \
                 time.mktime(time.strptime(metadata['mtime'], DATE_FORMAT))
 
+    file_path = layoutmanager.get_instance().get_data_path(uid)
+    if 'filesize' not in metadata:
+        if os.path.exists(file_path):
+            metadata['filesize'] = int(os.stat(file_path).st_size)
+        else:
+            metadata['filesize'] = 0
+
     for key, value in metadata.items():
         try:
             f = open(os.path.join(metadata_path, key), 'w')
-- 
1.6.3.3



More information about the Sugar-devel mailing list