| 783 | |
| 784 | |
| 785 | class FolderMoveCommand(Command): |
| 786 | @staticmethod |
| 787 | def get_transition_key(record, encryption_key): |
| 788 | # transition key is the key of the object being moved |
| 789 | # encrypted with the shared folder key if going to a shared folder, |
| 790 | # or encrypted with the user's data key |
| 791 | if record.get('version', -1) >= 3: |
| 792 | tkey = crypto.encrypt_aes_v2(record['record_key_unencrypted'], encryption_key) |
| 793 | else: |
| 794 | tkey = crypto.encrypt_aes_v1(record['record_key_unencrypted'], encryption_key) |
| 795 | return utils.base64_url_encode(tkey) |
| 796 | |
| 797 | @staticmethod |
| 798 | def prepare_transition_keys(params, folder, keys, encryption_key): |
| 799 | for f_uid in folder.subfolders: |
| 800 | f = params.folder_cache[f_uid] |
| 801 | FolderMoveCommand.prepare_transition_keys(params, f, keys, encryption_key) |
| 802 | |
| 803 | sf = params.subfolder_cache[folder.uid] |
| 804 | transition_key = utils.base64_url_encode(crypto.encrypt_aes_v1(sf['folder_key_unencrypted'], encryption_key)) |
| 805 | keys.append({ |
| 806 | 'uid': folder.uid, |
| 807 | 'key': transition_key |
| 808 | }) |
| 809 | if folder.uid in params.subfolder_record_cache: |
| 810 | for r_uid in params.subfolder_record_cache[folder.uid]: |
| 811 | rec = params.record_cache[r_uid] |
| 812 | transition_key = FolderMoveCommand.get_transition_key(rec, encryption_key) |
| 813 | keys.append({ |
| 814 | 'uid': r_uid, |
| 815 | 'key': transition_key |
| 816 | }) |
| 817 | |
| 818 | def get_parser(self): |
| 819 | return mv_parser |
| 820 | |
| 821 | def is_move(self): |
| 822 | return True |
| 823 | |
| 824 | def execute(self, params, **kwargs): |
| 825 | src_path = kwargs['src'] if 'src' in kwargs else None |
| 826 | dst_path = kwargs['dst'] if 'dst' in kwargs else None |
| 827 | |
| 828 | if not src_path or not dst_path: |
| 829 | parser = self.get_parser() |
| 830 | parser.print_help() |
| 831 | return |
| 832 | |
| 833 | if dst_path in params.folder_cache: |
| 834 | dst_folder = params.folder_cache[dst_path] |
| 835 | else: |
| 836 | dst = try_resolve_path(params, dst_path) |
| 837 | if dst is None: |
| 838 | raise CommandError('mv', 'Destination path should be existing folder') |
| 839 | dst_folder, name = dst |
| 840 | if len(name) > 0: |
| 841 | raise CommandError('mv', 'Destination path should be existing folder') |
| 842 |
no outgoing calls