A little merge script cleanup
[elliptics.git] / srw / pohmelfs_rename.py
blob5f74b2026f96a8b5cdca508224c7e2865c12cc93
1 import struct
3 d = {'script' : 'rename', 'dentry_name' : pohmelfs_dentry_name}
5 def pohmelfs_upload_dentry(new_dir_id, new_name, inode_info):
6 s = sstable()
7 try:
8 dir_content = n.read_data(new_dir_id, pohmelfs_offset, pohmelfs_size, pohmelfs_aflags, pohmelfs_ioflags_read)
9 s.load(dir_content)
10 except:
11 if not 'No such file or directory' in str(e):
12 raise
13 s.init(len(inode_info))
15 s.insert(new_name, inode_info, True)
16 content = str(s.save())
18 pohmelfs_write(new_dir_id, content)
20 logging.info("uploaded directory content hosting new name %s", new_name, extra=d)
22 try:
23 binary_data = __input_binary_data_tuple[0]
24 old_dir_id = elliptics_id(list(binary_data[0:64]), pohmelfs_group_id, pohmelfs_column)
25 new_dir_id = elliptics_id(list(binary_data[64:128]), pohmelfs_group_id, pohmelfs_column)
27 inode_info = binary_data[128:128+80]
28 new_name = str(binary_data[128+80:])
30 s = sstable()
31 dir_content = n.read_data(old_dir_id, pohmelfs_offset, pohmelfs_size, pohmelfs_aflags, pohmelfs_ioflags_read)
32 s.load(dir_content)
34 ret = s.search(pohmelfs_dentry_name)
35 if not ret:
36 raise KeyError("no entry")
38 if binary_data[0:64] != binary_data[64:128]:
39 pohmelfs_upload_dentry(new_dir_id, new_name, str(inode_info))
40 else:
41 s.insert(new_name, str(inode_info), True)
43 s.delete(pohmelfs_dentry_name)
44 content = str(s.save())
46 pohmelfs_write(old_dir_id, content)
48 __return_data = 'ok'
49 #logging.info("renamed -> %s: %s", new_name, parse(content), extra=d)
50 logging.info("renamed -> %s", new_name, extra=d)
52 s = None
53 content = None
55 gc.collect()
57 except KeyError as e:
58 logging.error("key error: %s", e.__str__(), extra=d)
59 __return_data = 'key error: ' + e.__str__()
60 except Exception as e:
61 logging.error("generic error: %s", e.__str__(), extra=d)
62 __return_data = 'error: ' + e.__str__()