Set last access and last modified times in layertools extract

Closes gh-28167
This commit is contained in:
Andy Wilkinson
2021-10-04 10:04:43 +01:00
parent 6d3e1734f6
commit b7a2a2d5e0
2 changed files with 64 additions and 16 deletions

View File

@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributeView;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
@@ -96,7 +97,13 @@ class ExtractCommand extends Command {
try (OutputStream out = new FileOutputStream(file)) {
StreamUtils.copy(zip, out);
}
Files.setAttribute(file.toPath(), "creationTime", entry.getCreationTime());
try {
Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class)
.setTimes(entry.getLastModifiedTime(), entry.getLastAccessTime(), entry.getCreationTime());
}
catch (IOException ex) {
// File system does not support setting time attributes. Continue.
}
}
private void mkParentDirs(File file) throws IOException {