private void EnsureLocalConflictByConflictFile(string conflictFilePath) { var conflict = _context.Conflicts.FirstOrDefault(current => current.ConflictFilePath == conflictFilePath); // conflict does not exist in database // actions: add new entity if (conflict == null) { _logger.LogDebug($"Conflict entity does not exist. Actions(s): Add new entity."); var originalFilePath = _regex_replace.Replace(conflictFilePath, string.Empty); conflict = new Conflict() { OriginalFilePath = originalFilePath, ConflictFilePath = conflictFilePath }; _context.Conflicts.Add(conflict); } else { _logger.LogDebug($"Conflict entity already exists. Actions(s): do nothing."); } }
private async Task <bool> CheckConflict(Conflict conflict) { var remoteItem = _context.RemoteStates.FirstOrDefault(current => current.GetItemPath() == conflict.OriginalFilePath); var originalDriveItem = conflict.OriginalFilePath.ToDriveItem(DriveItemType.File); // original file exists locally if (await _localDrive.ExistsAsync(originalDriveItem)) { _logger.LogDebug($"Original file exists locally."); var conflictDriveItem = conflict.ConflictFilePath.ToDriveItem(DriveItemType.File); // conflict file exists locally // actions: do nothing - user must delete or rename conflict file manually if (await _localDrive.ExistsAsync(conflictDriveItem)) { _logger.LogDebug($"Conflict file exists locally. Action(s): do nothing."); } // conflict file does not exist locally, i.e. conflict is solved else { _logger.LogDebug($"Conflict file does not exist locally."); // remote file is tracked in database if (remoteItem != null) { _logger.LogDebug($"Remote file is tracked in database."); // hashes are equal // actions: do nothing if (await _localDrive.GetHashAsync(originalDriveItem) == remoteItem.QuickXorHash) { _logger.LogDebug($"File is unchanged. Action(s): do nothing."); } // actions: upload file and replace remote version else { _logger.LogInformation($"File was modified. Action(s): upload and replace file."); originalDriveItem = await _localDrive.ToFullDriveItem(originalDriveItem); var driveItem = await _remoteDrive.CreateOrUpdateAsync(originalDriveItem); _context.RemoteStates.Add(driveItem.ToRemoteState()); } } // remote file is not tracked in database (e.g. upload failed previously) // actions: upload file else { _logger.LogInformation($"Remote file is not tracked in database. Action(s): upload file."); originalDriveItem = await _localDrive.ToFullDriveItem(originalDriveItem); var driveItem = await _remoteDrive.CreateOrUpdateAsync(originalDriveItem); _context.RemoteStates.Add(driveItem.ToRemoteState()); } return(true); } } // original file does not exist locally // actions: do nothing - user must delete or rename conflict file manually else { _logger.LogDebug($"Original file does not exist locally. Action(s): do nothing."); } return(false); }