1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
goreleaser/internal/gio/chtimes.go
Carlos Alexandro Becker b9a08c4dc9
refactor: gio.Chtimes (#4191)
we're repeating this quite a bit

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-07-15 16:33:40 -03:00

25 lines
454 B
Go

package gio
import (
"fmt"
"os"
"strconv"
"time"
)
// Chtimes applies the given ts to the given path.
func Chtimes(path, ts string) error {
if ts == "" {
return nil
}
modUnix, err := strconv.ParseInt(ts, 10, 64)
if err != nil {
return fmt.Errorf("chtimes: %s: %w", path, err)
}
modTime := time.Unix(modUnix, 0)
if err := os.Chtimes(path, modTime, modTime); err != nil {
return fmt.Errorf("chtimes: %s: %w", path, err)
}
return nil
}