Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local disk cache: part 1 #530

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading