Skip to content

Commit

Permalink
[7.0.0] Follow symlinks for setLastModifiedTime. (bazelbuild#20321)
Browse files Browse the repository at this point in the history
The method is documented as such in FileSystem.

PiperOrigin-RevId: 585581298
Change-Id: I9838d97747f820784db2f9fd68425d4d27b8b857
  • Loading branch information
tjgq authored Nov 27, 2023
1 parent b854505 commit 4260c15
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ protected SeekableByteChannel createReadWriteByteChannel(PathFragment path) thro

@Override
public void setLastModifiedTime(PathFragment path, long newTime) throws IOException {
path = resolveSymbolicLinks(path).asFragment();

FileNotFoundException remoteException = null;
try {
// We can't set mtime for a remote file, set mtime of in-memory file node instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,51 @@ public void statAndExists_notFound() throws Exception {
FileNotFoundException.class, () -> actionFs.stat(path, /* followSymlinks= */ true));
}

@Test
public void setLastModifiedTime_forRemoteOutputTree() throws Exception {
RemoteActionFileSystem actionFs = (RemoteActionFileSystem) createActionFileSystem();
Artifact artifact = ActionsTestUtil.createArtifact(outputRoot, "out");
PathFragment path = artifact.getPath().asFragment();
injectRemoteFile(actionFs, artifact.getPath().asFragment(), "remote contents");

actionFs.getPath(path).setLastModifiedTime(1234567890);
assertThat(actionFs.getPath(path).getLastModifiedTime()).isEqualTo(1234567890);
}

@Test
public void setLastModifiedTime_forLocalFilesystem() throws Exception {
RemoteActionFileSystem actionFs = (RemoteActionFileSystem) createActionFileSystem();
Artifact artifact = ActionsTestUtil.createArtifact(outputRoot, "out");
PathFragment path = artifact.getPath().asFragment();
writeLocalFile(actionFs, artifact.getPath().asFragment(), "local contents");

actionFs.getPath(path).setLastModifiedTime(1234567890);
assertThat(actionFs.getPath(path).getLastModifiedTime()).isEqualTo(1234567890);
}

@Test
public void setLastModifiedTime_followSymlinks(
@TestParameter FilesystemTestParam from, @TestParameter FilesystemTestParam to)
throws Exception {
RemoteActionFileSystem actionFs = (RemoteActionFileSystem) createActionFileSystem();
FileSystem fromFs = from.getFilesystem(actionFs);
FileSystem toFs = to.getFilesystem(actionFs);

PathFragment linkPath = getOutputPath("sym");
PathFragment targetPath = getOutputPath("target");
fromFs.getPath(linkPath).createSymbolicLink(execRoot.getRelative(targetPath).asFragment());

if (toFs.equals(actionFs.getLocalFileSystem())) {
writeLocalFile(actionFs, targetPath, "content");
} else {
injectRemoteFile(actionFs, targetPath, "content");
}

actionFs.getPath(linkPath).setLastModifiedTime(1234567890);
assertThat(actionFs.getPath(linkPath).getLastModifiedTime()).isEqualTo(1234567890);
assertThat(actionFs.getPath(targetPath).getLastModifiedTime()).isEqualTo(1234567890);
}

@Test
public void getDigest_fromInputArtifactData_forLocalArtifact() throws Exception {
ActionInputMap inputs = new ActionInputMap(1);
Expand Down

0 comments on commit 4260c15

Please sign in to comment.