Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions wasi-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@
<exclude>tests/c/testsuite/wasm32-wasip1/pwrite-with-append.wasm</exclude>
<!-- dangling symlinks are not supported -->
<exclude>tests/rust/testsuite/wasm32-wasip1/dangling_symlink.wasm</exclude>
<!-- symlinks filestat is not supported -->
<exclude>tests/rust/testsuite/wasm32-wasip1/symlink_filestat.wasm</exclude>
<!-- fd_fdstat_set_rights is not implemented -->
<exclude>tests/rust/testsuite/wasm32-wasip1/fd_fdstat_set_rights.wasm</exclude>
<exclude>tests/rust/testsuite/wasm32-wasip1/truncation_rights.wasm</exclude>
Expand Down
34 changes: 34 additions & 0 deletions wasi-tests/src/test/java/run/endive/wasi/WasiPreview1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.createDirectory;
import static java.nio.file.Files.createSymbolicLink;
import static java.nio.file.Files.getLastModifiedTime;
import static java.nio.file.Files.writeString;
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -260,6 +263,37 @@ public void fdReadNegativeIovLenShouldReturnEinval() throws IOException {
}
}

@Test
public void pathFilestatSetTimesHonoursLookupFlags() throws IOException {
try (var fs = newZeroFs()) {
Path root = fs.getPath("test");
createDirectory(root);
writeString(root.resolve("file"), "hello");
createSymbolicLink(root.resolve("link"), fs.getPath("file"));
long fileTime = getLastModifiedTime(root.resolve("file")).toMillis();
try (var wasi = wasiWithDirectory(root.toString(), root)) {
int result =
wasi.pathFilestatSetTimes(
3, 0, "link", 0, SECONDS.toNanos(1), WasiFstFlags.MTIM);
assertEquals(WasiErrno.ESUCCESS.value(), result);
assertEquals(
1000, getLastModifiedTime(root.resolve("link"), NOFOLLOW_LINKS).toMillis());
assertEquals(fileTime, getLastModifiedTime(root.resolve("file")).toMillis());

result =
wasi.pathFilestatSetTimes(
3,
WasiLookupFlags.SYMLINK_FOLLOW,
"link",
0,
SECONDS.toNanos(2),
WasiFstFlags.MTIM);
assertEquals(WasiErrno.ESUCCESS.value(), result);
assertEquals(2000, getLastModifiedTime(root.resolve("file")).toMillis());
}
}
}

@Test
public void symlinkEscapeShouldReturnEacces() throws IOException {
Path tmpDir = java.nio.file.Files.createTempDirectory("wasi-symlink-test");
Expand Down
8 changes: 5 additions & 3 deletions wasi/src/main/java/run/endive/wasi/WasiPreview1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ public int pathFilestatSetTimes(
return wasiResult(WasiErrno.EACCES);
}

return wasiResult(setFileTimes(path, modifiedTime, accessTime, fstFlags));
return wasiResult(
setFileTimes(path, modifiedTime, accessTime, fstFlags, toLinkOptions(lookupFlags)));
}

private static final class ResolvedSymlink {
Expand Down Expand Up @@ -1798,7 +1799,8 @@ private long clockTime(int clockId) {
}
}

private WasiErrno setFileTimes(Path path, long modifiedTime, long accessTime, int flags) {
private WasiErrno setFileTimes(
Path path, long modifiedTime, long accessTime, int flags, LinkOption... options) {
boolean modifiedSet = flagSet(flags, WasiFstFlags.MTIM);
boolean modifiedNow = flagSet(flags, WasiFstFlags.MTIM_NOW);
boolean accessSet = flagSet(flags, WasiFstFlags.ATIM);
Expand All @@ -1812,7 +1814,7 @@ private WasiErrno setFileTimes(Path path, long modifiedTime, long accessTime, in
FileTime lastAccessTime = toFileTime(accessTime, accessSet, accessNow);

try {
Files.getFileAttributeView(path, BasicFileAttributeView.class)
Files.getFileAttributeView(path, BasicFileAttributeView.class, options)
.setTimes(lastModifiedTime, lastAccessTime, null);
} catch (IOException e) {
return WasiErrno.EIO;
Expand Down
Loading