talos

Форк
0
/
touch.go 
36 строк · 799.0 Байт
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package utils
6

7
import (
8
	"io/fs"
9
	"os"
10
	"path/filepath"
11
	"time"
12
)
13

14
// TouchFiles updates mtime for all the files under root if SOURCE_DATE_EPOCH is set.
15
func TouchFiles(printf func(string, ...any), root string) error {
16
	epochInt, ok, err := SourceDateEpoch()
17
	if err != nil {
18
		return err
19
	}
20

21
	if !ok {
22
		return nil
23
	}
24

25
	timestamp := time.Unix(epochInt, 0)
26

27
	printf("changing timestamps under %q to %s", root, timestamp)
28

29
	return filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
30
		if err != nil {
31
			return err
32
		}
33

34
		return os.Chtimes(path, timestamp, timestamp)
35
	})
36
}
37

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.