119 SPDX-FileCopyrightText headers and the README's licence line. The distinction that matters here: LINUXexpert-org appears in this repository in two completely different roles. As a copyright holder in the SPDX headers, which is what changes, and as the GitHub organisation in the module path and 64 import statements, which does not -- the repository still lives at github.com/LINUXexpert-org/stalwart-migrator, and rewriting that would not be a licence change, it would break the build. Both replacements are anchored to their copyright forms, so an import path cannot match either. Import count is 64 before and after, and go.mod is untouched. LICENSE untouched: the FSF's copyright on the GPL text and the "<name of author>" placeholders are not ours to edit. go vet, go build and go test all clean.
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package backup
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// PreserveBinary moves the currently-installed binary aside to
|
|
// "<binaryPath>.v<sourceVersion>" so cutover can install the new one at the
|
|
// original path while the exact old binary stays on disk - an operator
|
|
// putting the machine back by hand needs it, and re-downloading a specific
|
|
// old release is not something to be doing under pressure. It never deletes
|
|
// the old binary, and it's idempotent: if a prior attempt at this run
|
|
// already preserved it, calling this again just returns the existing
|
|
// preserved path rather than erroring on a missing source file.
|
|
func PreserveBinary(binaryPath, sourceVersion string) (preservedPath string, err error) {
|
|
if sourceVersion == "" {
|
|
return "", fmt.Errorf("backup: cannot preserve %s without a source version to suffix it with", binaryPath)
|
|
}
|
|
preservedPath = binaryPath + ".v" + sourceVersion
|
|
|
|
if _, statErr := os.Stat(preservedPath); statErr == nil {
|
|
return preservedPath, nil
|
|
} else if !os.IsNotExist(statErr) {
|
|
return "", fmt.Errorf("backup: stat %s: %w", preservedPath, statErr)
|
|
}
|
|
|
|
if err := os.Rename(binaryPath, preservedPath); err != nil {
|
|
return "", fmt.Errorf("backup: preserve %s as %s: %w", binaryPath, preservedPath, err)
|
|
}
|
|
return preservedPath, nil
|
|
}
|