Skip to content

Commit

Permalink
set last access and create times
Browse files Browse the repository at this point in the history
fixes #199
  • Loading branch information
hboutemy authored and aalmiray committed Sep 14, 2023
1 parent 736e8a5 commit f3e629b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/src/main/java/org/moditect/commands/AddModuleInfo.java
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.HashMap;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void run() {
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING);
Files.setLastModifiedTime(path, toFileTime(timestamp));
setTimes(path, toFileTime(timestamp));
}
else {
Path path = zipfs.getPath("META-INF/versions", jvmVersion.toString(), "module-info.class");
Expand All @@ -130,11 +131,11 @@ public void run() {
StandardOpenOption.TRUNCATE_EXISTING);
FileTime lastModifiedTime = toFileTime(timestamp);
// module-info.class
Files.setLastModifiedTime(path, lastModifiedTime);
setTimes(path, lastModifiedTime);
// jvmVersion
Files.setLastModifiedTime(path.getParent(), lastModifiedTime);
setTimes(path.getParent(), lastModifiedTime);
// versions
Files.setLastModifiedTime(path.getParent().getParent(), lastModifiedTime);
setTimes(path.getParent().getParent(), lastModifiedTime);

Path manifestPath = zipfs.getPath("META-INF/MANIFEST.MF");
Manifest manifest;
Expand All @@ -150,7 +151,7 @@ public void run() {
try (OutputStream manifestOs = Files.newOutputStream(manifestPath, StandardOpenOption.TRUNCATE_EXISTING)) {
manifest.write(manifestOs);
}
Files.setLastModifiedTime(manifestPath, lastModifiedTime);
setTimes(manifestPath, lastModifiedTime);
}
}
catch (IOException e) {
Expand All @@ -161,4 +162,8 @@ public void run() {
private FileTime toFileTime(Instant timestamp) {
return FileTime.from(timestamp != null ? timestamp : Instant.now());
}

private void setTimes(Path path, FileTime time) throws IOException {
Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes(time, time, time);
}
}

0 comments on commit f3e629b

Please sign in to comment.