()
| 280 | } |
| 281 | |
| 282 | func (up *Updater) switchOutputToFile() (io.Closer, error) { |
| 283 | var logFilePath string |
| 284 | exePath, err := os.Executable() |
| 285 | if err != nil { |
| 286 | logFilePath = up.startNewLogFile(updaterPrefix, os.Getenv(winVersionEnv)) |
| 287 | } else { |
| 288 | // Use the same suffix as the self-copy executable. |
| 289 | suffix := strings.TrimSuffix(strings.TrimPrefix(filepath.Base(exePath), updaterPrefix), ".exe") |
| 290 | logFilePath = up.startNewLogFile(updaterPrefix, os.Getenv(winVersionEnv)+suffix) |
| 291 | } |
| 292 | |
| 293 | up.Logf("writing update output to: %s", logFilePath) |
| 294 | logFile, err := os.Create(logFilePath) |
| 295 | if err != nil { |
| 296 | return nil, err |
| 297 | } |
| 298 | |
| 299 | up.Logf = func(m string, args ...any) { |
| 300 | fmt.Fprintf(logFile, m+"\n", args...) |
| 301 | } |
| 302 | up.Stdout = logFile |
| 303 | up.Stderr = logFile |
| 304 | return logFile, nil |
| 305 | } |
| 306 | |
| 307 | // startNewLogFile returns a name for a new log file. |
| 308 | // It cleans up any old log files with the same baseNamePrefix. |
no test coverage detected