mergin/merginproject.py
def apply_pull_changes(self, changes, temp_dir, user_name):
        """
        Apply changes pulled from server.

        Update project files according to file changes. Apply changes to geodiff basefiles as well
        so they are up to date with server. In case of conflicts create backups from locally modified versions.

        .. seealso:: self.get_pull_changes

        :param changes: metadata for pulled files
        :type changes: dict[str, list[dict]]
        :param temp_dir: directory with downloaded files from server
        :type temp_dir: str
        :returns: files where conflicts were found
        :rtype: list[str]
        """
        conflicts = []
        local_changes = self.get_push_changes()
        modified = {}
        for f in local_changes["added"] + local_changes["updated"]:
            modified.update({f['path']: f})

        local_files_map = {}
        for f in self.inspect_files():
            local_files_map.update({f['path']: f})

        for k, v in changes.items():
            for item in v:
                path = item['path']
                src = self.fpath(path, temp_dir)
                dest = self.fpath(path)
                basefile = self.fpath_meta(path)

                # special care is needed for geodiff files
                # 'src' here is server version of file and 'dest' is locally modified
                if self.is_versioned_file(path) and k == 'updated':
                    if path in modified:
                        conflict = self.update_with_rebase(path, src, dest, basefile, temp_dir, user_name)
                        if conflict:
                            conflicts.append(conflict)
                    else:
                        # The local file is not modified -> no rebase needed.
                        # We just apply the diff between our copy and server to both the local copy and its basefile
                        self.update_without_rebase(path, src, dest, basefile, temp_dir)
                else:
                    # backup if needed
                    if path in modified and item['checksum'] != local_files_map[path]['checksum']:
                        conflict = self.create_conflicted_copy(path, user_name)
                        conflicts.append(conflict)

                    if k == 'removed':
                        if os.path.exists(dest):
                            os.remove(dest)
                        else:
                            # the file could be deleted via web interface AND also manually locally -> just log it
                            self.log.warning(f"File to be removed locally doesn't exist: {dest}")
                        if self.is_versioned_file(path):
                            os.remove(basefile)
                    else:
                        if self.is_versioned_file(path):
                            self.geodiff.make_copy_sqlite(src, dest)
                            self.geodiff.make_copy_sqlite(src, basefile)
                        else:
                            shutil.copy(src, dest)

        return conflicts

        Apply changes pulled from server.

        Update project files according to file changes. Apply changes to geodiff basefiles as well
        so they are up to date with server. In case of conflicts create backups from locally modified versions.

        .. seealso:: self.get_pull_changes

        :param changes: metadata for pulled files
        :type changes: dict[str, list[dict]]
        :param temp_dir: directory with downloaded files from server
        :type temp_dir: str
        :returns: files where conflicts were found
        :rtype: list[str]
        
Apply changes pulled from server.
Update project files according to file changes. Apply changes to geodiff basefiles as well
so they are up to date with server. In case of conflicts create backups from locally modified versions.


Apply changes pulled from server . Update project files according to file changes . Apply changes to geodiff basefiles as well so they are up to date with server . In case of conflicts create backups from locally modified versions .
def apply_pull_changes(self, changes, temp_dir, user_name):
        conflicts = []
        local_changes = self.get_push_changes()
        modified = {}
        for f in local_changes["added"] + local_changes["updated"]:
            modified.update({f['path']: f})
        local_files_map = {}
        for f in self.inspect_files():
            local_files_map.update({f['path']: f})
        for k, v in changes.items():
            for item in v:
                path = item['path']
                src = self.fpath(path, temp_dir)
                dest = self.fpath(path)
                basefile = self.fpath_meta(path)
                if self.is_versioned_file(path) and k == 'updated':
                    if path in modified:
                        conflict = self.update_with_rebase(path, src, dest, basefile, temp_dir, user_name)
                        if conflict:
                            conflicts.append(conflict)
                    else:
                        self.update_without_rebase(path, src, dest, basefile, temp_dir)
                else:
                    if path in modified and item['checksum'] != local_files_map[path]['checksum']:
                        conflict = self.create_conflicted_copy(path, user_name)
                        conflicts.append(conflict)
                    if k == 'removed':
                        if os.path.exists(dest):
                            os.remove(dest)
                        else:
                            self.log.warning(f"File to be removed locally doesn't exist: {dest}")
                        if self.is_versioned_file(path):
                            os.remove(basefile)
                    else:
                        if self.is_versioned_file(path):
                            self.geodiff.make_copy_sqlite(src, dest)
                            self.geodiff.make_copy_sqlite(src, basefile)
                        else:
                            shutil.copy(src, dest)
        return conflicts
def apply_pull_changes ( self , changes , temp_dir , user_name ) : conflicts = [ ] local_changes = self . get_push_changes ( ) modified = { } for f in local_changes [ "added" ] + local_changes [ "updated" ] : modified . update ( { f [ 'path' ] : f } ) local_files_map = { } for f in self . inspect_files ( ) : local_files_map . update ( { f [ 'path' ] : f } ) for k , v in changes . items ( ) : for item in v : path = item [ 'path' ] src = self . fpath ( path , temp_dir ) dest = self . fpath ( path ) basefile = self . fpath_meta ( path ) if self . is_versioned_file ( path ) and k == 'updated' : if path in modified : conflict = self . update_with_rebase ( path , src , dest , basefile , temp_dir , user_name ) if conflict : conflicts . append ( conflict ) else : self . update_without_rebase ( path , src , dest , basefile , temp_dir ) else : if path in modified and item [ 'checksum' ] != local_files_map [ path ] [ 'checksum' ] : conflict = self . create_conflicted_copy ( path , user_name ) conflicts . append ( conflict ) if k == 'removed' : if os . path . exists ( dest ) : os . remove ( dest ) else : self . log . warning ( f"File to be removed locally doesn't exist: {dest}" ) if self . is_versioned_file ( path ) : os . remove ( basefile ) else : if self . is_versioned_file ( path ) : self . geodiff . make_copy_sqlite ( src , dest ) self . geodiff . make_copy_sqlite ( src , basefile ) else : shutil . copy ( src , dest ) return conflicts
Apply changes pulled from server.
Apply changes pulled from server .
"""
        Apply changes pulled from server.

        Update project files according to file changes. Apply changes to geodiff basefiles as well
        so they are up to date with server. In case of conflicts create backups from locally modified versions.

        .. seealso:: self.get_pull_changes

        :param changes: metadata for pulled files
        :type changes: dict[str, list[dict]]
        :param temp_dir: directory with downloaded files from server
        :type temp_dir: str
        :returns: files where conflicts were found
        :rtype: list[str]
        """ # special care is needed for geodiff files # 'src' here is server version of file and 'dest' is locally modified # The local file is not modified -> no rebase needed. # We just apply the diff between our copy and server to both the local copy and its basefile # backup if needed # the file could be deleted via web interface AND also manually locally -> just log it
files where conflicts were found
files where conflicts were found
list[str]
self
changes
metadata for pulled files
metadata for pulled files
temp_dir
directory with downloaded files from server
directory with downloaded files from server
user_name