Skip to content

Commit

Permalink
Redact launcher friend names from FactoryGame.log (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Sep 24, 2024
1 parent d8a3236 commit 6dc0c08
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/app/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log/slog"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -47,6 +48,7 @@ func addDefaultFactoryGameLog(writer *zip.Writer) error {
if err != nil {
return fmt.Errorf("failed to get user cache dir: %w", err)
}
// TODO redact this file with redactFactoryGameLog
err = utils.AddFileToZip(writer, filepath.Join(cacheDir, "FactoryGame", "Saved", "Logs", "FactoryGame.log"), "FactoryGame.log")
if err != nil {
if errors.Is(err, os.ErrNotExist) {
Expand All @@ -62,27 +64,38 @@ func addDefaultFactoryGameLog(writer *zip.Writer) error {
return nil
}

func redactFactoryGameLog(bytes []byte) []byte {
re := regexp.MustCompile(`(Added friend with nickname ').*(' on online context)`)
return re.ReplaceAll(bytes, []byte("${1}REDACTED${2}"))
}

func addInstallFactoryGameLog(writer *zip.Writer, install *common.Installation) error {
logPath := filepath.Join(install.SavedPath, "Logs", "FactoryGame.log")
d, err := ficsitcli.FicsitCLI.GetInstallation(install.Path).GetDisk()
if err != nil {
return fmt.Errorf("failed to get disk for installation: %w", err)
}

logExists, err := d.Exists(logPath)
if err != nil {
return fmt.Errorf("failed to check if log exists: %w", err)
}
if !logExists {
return fmt.Errorf("log does not exist")
}
bytes, err := d.Read(logPath)

bytes, err := os.ReadFile(logPath)
if err != nil {
return fmt.Errorf("failed to read log file: %w", err)
}

bytes = redactFactoryGameLog(bytes)

logFile, err := writer.Create(getLogNameForInstall(install))
if err != nil {
return fmt.Errorf("failed to create log file in zip: %w", err)
}

_, err = logFile.Write(bytes)
if err != nil {
return fmt.Errorf("failed to write log file to zip: %w", err)
Expand Down

0 comments on commit 6dc0c08

Please sign in to comment.