CFG_VER/APP_VER in the env file: invalid configs replaced, updates follow APP_VER (dev/stable/pin)
This commit is contained in:
@@ -172,28 +172,14 @@ func Install(configPath string, copyBin bool, version string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A service has no console: without LOG_FILE the output vanishes.
|
||||
// With no config at all, install a fully commented sample covering
|
||||
// every setting (only LOG_FILE active). An existing installer-written
|
||||
// config from an older version gets any new settings appended; any
|
||||
// other existing config just gets a LOG_FILE line if it has none.
|
||||
// A service has no console: without LOG_FILE the output vanishes, so
|
||||
// the sample pre-wires it to ProgramData. Missing configs get a
|
||||
// fresh sample; installer-written ones from older versions get new
|
||||
// settings appended; anything without CFG_VER is invalid and gets
|
||||
// replaced (backup kept as .bak).
|
||||
logPath := filepath.Join(dataDir, "gpu-turnstile.log")
|
||||
data, readErr := os.ReadFile(targetCfg)
|
||||
switch {
|
||||
case os.IsNotExist(readErr):
|
||||
if err := os.WriteFile(targetCfg, []byte(config.SampleEnv(version, logPath)), 0o644); err != nil {
|
||||
return fmt.Errorf("write %s: %w", targetCfg, err)
|
||||
}
|
||||
case readErr != nil:
|
||||
return fmt.Errorf("read %s: %w", targetCfg, readErr)
|
||||
default:
|
||||
if synced, changed := config.SyncSample(string(data), version, logPath); changed {
|
||||
if err := os.WriteFile(targetCfg, []byte(synced), 0o644); err != nil {
|
||||
return fmt.Errorf("write %s: %w", targetCfg, err)
|
||||
}
|
||||
} else if err := ensureLogFile(targetCfg, logPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := syncEnvFile(targetCfg, version, logPath); err != nil {
|
||||
return err
|
||||
}
|
||||
configPath = targetCfg
|
||||
}
|
||||
@@ -329,30 +315,6 @@ func sameFileContent(a, b string) (bool, error) {
|
||||
return bytes.Equal(ba, bb), nil
|
||||
}
|
||||
|
||||
// ensureLogFile makes sure the env file at path sets LOG_FILE, creating
|
||||
// the file or appending the line as needed. An existing LOG_FILE= line
|
||||
// (even an empty one) is respected and left untouched.
|
||||
func ensureLogFile(path, logPath string) error {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("read %s: %w", path, err)
|
||||
}
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "LOG_FILE=") {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
s := string(data)
|
||||
if s != "" && !strings.HasSuffix(s, "\n") {
|
||||
s += "\n"
|
||||
}
|
||||
s += "LOG_FILE=" + logPath + "\n"
|
||||
if err := os.WriteFile(path, []byte(s), 0o644); err != nil {
|
||||
return fmt.Errorf("write %s: %w", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// copyFile copies src to dst (0755 on the new file).
|
||||
func copyFile(src, dst string) error {
|
||||
in, err := os.Open(src)
|
||||
|
||||
Reference in New Issue
Block a user