Skip to content

Commit

Permalink
Local disk cache: part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ola-rozenfeld committed Jan 31, 2024
1 parent 6dd3970 commit 6939738
Show file tree
Hide file tree
Showing 6 changed files with 656 additions and 0 deletions.
33 changes: 33 additions & 0 deletions go/pkg/diskcache/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "diskcache",
srcs = [
"atim_darwin.go",
"atim_linux.go",
"atim_windows.go",
"diskcache.go",
],
importpath = "github.com/bazelbuild/remote-apis-sdks/go/pkg/diskcache",
visibility = ["//visibility:public"],
deps = [
"//go/pkg/digest",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_golang_glog//:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

go_test(
name = "diskcache_test",
srcs = ["diskcache_test.go"],
embed = [":diskcache"],
deps = [
"//go/pkg/digest",
"//go/pkg/testutil",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_google_go_cmp//cmp:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
],
)
16 changes: 16 additions & 0 deletions go/pkg/diskcache/atim_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Utility to get the last accessed time on Darwin.
package diskcache

import (
"os"
"syscall"
"time"
)

func GetLastAccessTime(path string) (time.Time, error) {
info, err := os.Stat(path)
if err != nil {
return time.Time{}, err
}
return time.Unix(info.Sys().(*syscall.Stat_t).Atimespec.Unix()), nil
}
16 changes: 16 additions & 0 deletions go/pkg/diskcache/atim_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Utility to get the last accessed time on Linux.
package diskcache

import (
"os"
"syscall"
"time"
)

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

Check failure on line 13 in go/pkg/diskcache/atim_linux.go

View workflow job for this annotation

GitHub Actions / lint

error returned from external package is unwrapped: sig: func os.Stat(name string) (io/fs.FileInfo, error) (wrapcheck)
}
return time.Unix(info.Sys().(*syscall.Stat_t).Atim.Unix()), nil
}
18 changes: 18 additions & 0 deletions go/pkg/diskcache/atim_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Utility to get the last accessed time on Windows.
package diskcache

import (
"os"
"syscall"
"time"
)

// This will return correct values only if `fsutil behavior set disablelastaccess 0` is set.
// Tracking of last access time is disabled by default on Windows.
func GetLastAccessTime(path string) (time.Time, error) {
info, err := os.Stat(path)
if err != nil {
return time.Time{}, err
}
return time.Unix(0, info.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()), nil
}
Loading

0 comments on commit 6939738

Please sign in to comment.