mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-10 15:11:15 +02:00
This relies on changes in GRUB and other utilities to respect `SOURCE_DATE_EPOCH`. Variable `SOURCE_DATE_EPOCH` is set to the timestamp of the last git commit which makes it deterministic, but still changes for each release/commit. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
38 lines
779 B
Go
38 lines
779 B
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package pkg
|
|
|
|
import (
|
|
"io/fs"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// TouchFiles updates mtime for all the files under root if SOURCE_DATE_EPOCH is set.
|
|
func TouchFiles(root string) error {
|
|
epochInt, ok, err := SourceDateEpoch()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
timestamp := time.Unix(epochInt, 0)
|
|
|
|
log.Printf("changing timestamps under %q to %s", root, timestamp)
|
|
|
|
return filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return os.Chtimes(path, timestamp, timestamp)
|
|
})
|
|
}
|