Skip to content

Commit

Permalink
Also redact default log
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Sep 28, 2024
1 parent 22f3b89 commit 88a3cb9
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions backend/app/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ 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")
defaultLogPath := filepath.Join(cacheDir, "FactoryGame", "Saved", "Logs", "FactoryGame.log")
err = addLogFromPath(writer, defaultLogPath, "FactoryGame.log")
if err != nil {
if errors.Is(err, os.ErrNotExist) {
if runtime.GOOS != "windows" {
Expand All @@ -69,29 +69,15 @@ func redactFactoryGameLog(bytes []byte) []byte {
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")
}

func addLogFromPath(writer *zip.Writer, logPath string, zipFileName string) error {
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))
logFile, err := writer.Create(zipFileName)
if err != nil {
return fmt.Errorf("failed to create log file in zip: %w", err)
}
Expand All @@ -103,6 +89,24 @@ func addInstallFactoryGameLog(writer *zip.Writer, install *common.Installation)
return nil
}

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")
}

return addLogFromPath(writer, logPath, getLogNameForInstall(install))
}

func addFactoryGameLogs(writer *zip.Writer) {
err := addDefaultFactoryGameLog(writer)
if err != nil {
Expand All @@ -122,7 +126,8 @@ func addFactoryGameLogs(writer *zip.Writer) {

func getLogNameForInstall(install *common.Installation) string {
hash := sha256.Sum256([]byte(install.Path))
return fmt.Sprintf("FactoryGame_%s_%s_%s_%s.log", install.Location, install.Branch, install.Type, hex.EncodeToString(hash[:])[:8])
first8 := hex.EncodeToString(hash[:])[:8]
return fmt.Sprintf("FactoryGame_%s_%s_%s_%s.log", first8, install.Location, install.Branch, install.Type)
}

func addMetadata(writer *zip.Writer) error {
Expand Down

0 comments on commit 88a3cb9

Please sign in to comment.