1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/gio/chtimes.go

25 lines
454 B
Go
Raw Normal View History

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
}