Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7012856

(zipfs) Newly created entry in zip file system should set all file times non-null values.

    XMLWordPrintable

Details

    • b94
    • generic
    • generic
    • Verified

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              sherman Xueming Shen
              stephenh Stephen Hu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: