From 3c71860c40c026b3600eb654922d7accb6df8026 Mon Sep 17 00:00:00 2001 From: Tiago Quelhas Date: Tue, 24 Sep 2024 23:37:15 +0200 Subject: [PATCH] [7.4.0] Use NOW_SENTINEL_TIME when refreshing the mtime on a disk cache entry. (#23739) Fixes #23512. PiperOrigin-RevId: 678162004 Change-Id: If94854fa02a4ae457507e3d2b20227871f88b068 --- .../devtools/build/lib/remote/disk/DiskCacheClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java index caa6fe4b325aac..4af5d9fc85fb36 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java @@ -48,7 +48,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.time.Instant; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutorService; @@ -119,7 +118,9 @@ public DiskCacheClient( */ public boolean refresh(Path path) throws IOException { try { - path.setLastModifiedTime(Instant.now().toEpochMilli()); + // Use NOW_SENTINEL_TIME instead of obtaining the current time so that the operation succeeds + // even when the file has a different owner, as might be the case for a shared cache. + path.setLastModifiedTime(Path.NOW_SENTINEL_TIME); } catch (FileNotFoundException e) { return false; }