Logo Search packages:      
Sourcecode: ubuntuone-client version File versions

def ubuntuone::syncdaemon::sync::SyncStateMachineRunner::merge_directory (   self,
  event,
  params,
  hash 
)

Merge the server directory with the local one.

Definition at line 382 of file sync.py.

00382                                                   :
        """Merge the server directory with the local one."""
        new_files = []
        new_dirs = []
        deleted_files = []
        deleted_dirs = []
        moved = set()

        try:
            fd = self.m.fs.get_partial(node_id=self.key['node_id'],
                            share_id=self.key['share_id'])
        except InconsistencyError:
            self.key.remove_partial()
            self.key.set(server_hash=self.key['local_hash'])
            self.m.action_q.query([
                (self.key["share_id"], self.key["node_id"], "")])
            # we dont perform the merge, we try to re get it
            return


        items = dircontent.parse_dir_content(fd)
        server_dir = [ (o.utf8_name, o.node_type == DIRECTORY, o.uuid)
                        for o in items ]
        client_dir = self.m.fs.dir_content(self.key['path'])
        # XXX: lucio.torre: with huge dirs, this could take a while

        share = self.key['share_id']
        for name, isdir, uuid in server_dir:
            # we took the name as bytes already encoded in utf8
            # directly from dircontent!
            try:
                md = self.m.fs.get_by_node_id(share, uuid)
            except KeyError:
                # not there, a new thing
                if isdir:
                    new_dirs.append((share, uuid, name))
                else:
                    new_files.append((share, uuid, name))
                continue
            mdpath = self.m.fs.get_abspath(md.share_id, md.path)
            if mdpath != os.path.join(self.key['path'], name):
                # this was moved
                # mark as moved
                moved.add(uuid)
                # signal moved
                self.m.event_q.push("SV_MOVED",
                    share_id=md.share_id, node_id=uuid,
                    new_share_id=share, new_parent_id=self.key['node_id'],
                    new_name=name)


        for name, isdir, uuid in client_dir:
            if uuid is None:
                continue

            if not (name, isdir, uuid) in server_dir:
                # not there, a its gone on the server
                if uuid in moved:
                    # this was a move, dont delete
                    continue
                if isdir:
                    deleted_dirs.append((share, uuid))
                else:
                    deleted_files.append((share, uuid))


        parent_uuid = self.key['node_id']
        for share, uuid, name in new_files:
            self.m.event_q.push("SV_FILE_NEW", parent_id=parent_uuid,
                                node_id=uuid, share_id=share, name=name)
        for share, uuid, name in new_dirs:
            self.m.event_q.push("SV_DIR_NEW", parent_id=parent_uuid,
                                node_id=uuid, share_id=share, name=name)
        for share, uuid in deleted_files:
            self.m.event_q.push("SV_FILE_DELETED",
                                node_id=uuid, share_id=share)
        for share, uuid in deleted_dirs:
            self.m.event_q.push("SV_FILE_DELETED",
                                node_id=uuid, share_id=share)

        self.key.remove_partial()
        self.key.set(local_hash=hash)

    def new_file(self, event, params, share_id, node_id, parent_id, name):


Generated by  Doxygen 1.6.0   Back to index