Commit 6ffc448b authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Fix SSH FETCH

Don't die on duplicates, just report them.
parent 67fc0fba
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -313,19 +313,25 @@ func FetchDB(q *storage.Queries, login, nickname, username string) string {
	defer resp.Body.Close()
	scanner := bufio.NewScanner(resp.Body)
	keys := 0
	dups := 0
	for scanner.Scan() {
		keyline := string(bytes.TrimSpace(scanner.Bytes()))
		if err := AddDB(q, strings.ToUpper(login), keyline); err != nil {
			if err.Error() == "key already exists" {
				dups++
			} else {
				return fmt.Sprintf("ERROR: Failed to add key (%s).\n", err)
			}
		} else {
			keys++
		}
	}
	switch keys {
	case 0:
		return fmt.Sprintln("No keys added.")
	case 1:
		return fmt.Sprintln("Key is added.")
	default:
		return fmt.Sprintf("%d keys added.\n", keys)
		return fmt.Sprintf("%d new keys added (%d duplicates skipped).\n", keys, dups)
	}
}