-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dd3970
commit 1046709
Showing
6 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
return time.Unix(info.Sys().(*syscall.Stat_t).Atim.Unix()), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.