Skip to content

Commit 1046709

Browse files
committed
Local disk cache: part 1
1 parent 6dd3970 commit 1046709

File tree

6 files changed

+653
-0
lines changed

6 files changed

+653
-0
lines changed

go/pkg/diskcache/BUILD.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "diskcache",
5+
srcs = [
6+
"atim_darwin.go",
7+
"atim_linux.go",
8+
"atim_windows.go",
9+
"diskcache.go",
10+
],
11+
importpath = "github.com/bazelbuild/remote-apis-sdks/go/pkg/diskcache",
12+
visibility = ["//visibility:public"],
13+
deps = [
14+
"//go/pkg/digest",
15+
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
16+
"@com_github_golang_glog//:go_default_library",
17+
"@org_golang_google_protobuf//proto:go_default_library",
18+
],
19+
)
20+
21+
go_test(
22+
name = "diskcache_test",
23+
srcs = ["diskcache_test.go"],
24+
embed = [":diskcache"],
25+
deps = [
26+
"//go/pkg/digest",
27+
"//go/pkg/testutil",
28+
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
29+
"@com_github_google_go_cmp//cmp:go_default_library",
30+
"@com_github_pborman_uuid//:go_default_library",
31+
"@org_golang_x_sync//errgroup:go_default_library",
32+
],
33+
)

go/pkg/diskcache/atim_darwin.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Utility to get the last accessed time on Darwin.
2+
package diskcache
3+
4+
import (
5+
"os"
6+
"syscall"
7+
"time"
8+
)
9+
10+
func GetLastAccessTime(path string) (time.Time, error) {
11+
info, err := os.Stat(path)
12+
if err != nil {
13+
return time.Time{}, err
14+
}
15+
return time.Unix(info.Sys().(*syscall.Stat_t).Atimespec.Unix()), nil
16+
}

go/pkg/diskcache/atim_linux.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Utility to get the last accessed time on Linux.
2+
package diskcache
3+
4+
import (
5+
"os"
6+
"syscall"
7+
"time"
8+
)
9+
10+
func GetLastAccessTime(path string) (time.Time, error) {
11+
info, err := os.Stat(path)
12+
if err != nil {
13+
return time.Time{}, err
14+
}
15+
return time.Unix(info.Sys().(*syscall.Stat_t).Atim.Unix()), nil
16+
}

go/pkg/diskcache/atim_windows.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Utility to get the last accessed time on Windows.
2+
package diskcache
3+
4+
import (
5+
"os"
6+
"syscall"
7+
"time"
8+
)
9+
10+
// This will return correct values only if `fsutil behavior set disablelastaccess 0` is set.
11+
// Tracking of last access time is disabled by default on Windows.
12+
func GetLastAccessTime(path string) (time.Time, error) {
13+
info, err := os.Stat(path)
14+
if err != nil {
15+
return time.Time{}, err
16+
}
17+
return time.Unix(0, info.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()), nil
18+
}

0 commit comments

Comments
 (0)