-
Enhancement
-
Resolution: Fixed
-
P3
-
7
-
b94
-
generic
-
generic
-
Verified
Inside zip fs, when a new entry is created (either via copyTo, moveTo, createFile or createDirectory, etc), all file times - which are lastModifiedTime, lastAccessTime and creationTime - should be set to some non-null values. While currectly implementation only set lastModifiedTime, leaving lastAccessTime and creationTime as null.
And I think other Zip util classes like ZipOutputStream and ZipFile should also behave this way.
====Test Code====
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.*;
public class TestZFSentryTimes {
private static final String ZIP_FILE = "zip_file.zip";
private static final String FILE_ON_DEFAULT_FS = "file_on_dfs.file";
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Map<String, Object> env = new HashMap<String, Object>();
env.put("create", "true");
Path zip_file = Paths.get(ZIP_FILE);
zip_file.deleteIfExists();
FileSystem fs = FileSystems.newFileSystem(zip_file, env, null);
fs.getPath("file1.txt").createFile();
fs.close();
fs = FileSystems.newFileSystem(zip_file, env, null);
System.out.println("File Times of entry inside a zip file: ");
printTimes(fs.getPath("file1.txt"));
fs.close();
System.out.println("File Times of file on default fs: ");
Path file_on_dfs = Paths.get(FILE_ON_DEFAULT_FS);
file_on_dfs.deleteIfExists();
file_on_dfs.createFile();
printTimes(file_on_dfs);
}
private static void printTimes(Path path) throws IOException {
FileTime atime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().lastAccessTime();
FileTime mtime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().lastModifiedTime();
FileTime ctime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().creationTime();
System.out.println("mtime: " + mtime);
System.out.println("ctime: " + ctime);
System.out.println("atime: " + atime);
}
}
====End of Code====
Output:
=======
File Times of entry inside a zip file:
mtime: 2011-01-18T07:40:58Z
ctime: null
atime: null
File Times of file on default fs:
mtime: 2011-01-18T07:40:59.25Z
ctime: 2011-01-18T07:40:59.25Z
atime: 2011-01-18T07:40:59.25Z
And I think other Zip util classes like ZipOutputStream and ZipFile should also behave this way.
====Test Code====
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.*;
public class TestZFSentryTimes {
private static final String ZIP_FILE = "zip_file.zip";
private static final String FILE_ON_DEFAULT_FS = "file_on_dfs.file";
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Map<String, Object> env = new HashMap<String, Object>();
env.put("create", "true");
Path zip_file = Paths.get(ZIP_FILE);
zip_file.deleteIfExists();
FileSystem fs = FileSystems.newFileSystem(zip_file, env, null);
fs.getPath("file1.txt").createFile();
fs.close();
fs = FileSystems.newFileSystem(zip_file, env, null);
System.out.println("File Times of entry inside a zip file: ");
printTimes(fs.getPath("file1.txt"));
fs.close();
System.out.println("File Times of file on default fs: ");
Path file_on_dfs = Paths.get(FILE_ON_DEFAULT_FS);
file_on_dfs.deleteIfExists();
file_on_dfs.createFile();
printTimes(file_on_dfs);
}
private static void printTimes(Path path) throws IOException {
FileTime atime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().lastAccessTime();
FileTime mtime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().lastModifiedTime();
FileTime ctime = path.getFileAttributeView(BasicFileAttributeView.class).readAttributes().creationTime();
System.out.println("mtime: " + mtime);
System.out.println("ctime: " + ctime);
System.out.println("atime: " + atime);
}
}
====End of Code====
Output:
=======
File Times of entry inside a zip file:
mtime: 2011-01-18T07:40:58Z
ctime: null
atime: null
File Times of file on default fs:
mtime: 2011-01-18T07:40:59.25Z
ctime: 2011-01-18T07:40:59.25Z
atime: 2011-01-18T07:40:59.25Z
- relates to
-
JDK-8020230 ZipFileSystem throws unexpected end of ZLIB input stream when copying zip file
-
- Closed
-