File: modkey_other.go

package info (click to toggle)
golang-github-evanw-esbuild 0.25.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,236 kB
  • sloc: javascript: 28,602; makefile: 856; sh: 17
file content (35 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//go:build !darwin && !freebsd && !linux
// +build !darwin,!freebsd,!linux

package fs

import (
	"os"
	"time"
)

var zeroTime time.Time

func modKey(path string) (ModKey, error) {
	info, err := os.Stat(path)
	if err != nil {
		return ModKey{}, err
	}

	// We can't detect changes if the file system zeros out the modification time
	mtime := info.ModTime()
	if mtime == zeroTime || mtime.Unix() == 0 {
		return ModKey{}, modKeyUnusable
	}

	// Don't generate a modification key if the file is too new
	if mtime.Add(modKeySafetyGap * time.Second).After(time.Now()) {
		return ModKey{}, modKeyUnusable
	}

	return ModKey{
		size:      info.Size(),
		mtime_sec: mtime.Unix(),
		mode:      uint32(info.Mode()),
	}, nil
}