Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-271516

Time information of files in backups is lost

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.6, 24w18a, 1.21 Pre-Release 2, 1.21
    • None
    • Confirmed
    • Save Data
    • Normal
    • Platform

      Steps to reproduce:

      1. Create a backup of a world
      2. Open the backup and find that the last modified times of files inside are absent.

      As a result, when replacing the original save with a backup, the time information, which indicates when a given area is touched for the last time and when a player joined the save for the last time, etc., would be lost.

      Possible solution

      Following is the vanilla implementation to add a file to a backup.

       

      ZipEntry zipEntry = new ZipEntry(string);
      zipOutputStream.putNextEntry(zipEntry);
      com.google.common.io.Files.asByteSource(path.toFile()).copyTo(zipOutputStream);
      zipOutputStream.closeEntry(); 

      The ZipEntry class provides a few methods like setLastModifiedTime() to set the time information of corresponding files, by using them we can easily do it.

       

      ZipEntry zipEntry = new ZipEntry(string); 
      zipEntry.setLastModifiedTime(Files.getLastModifiedTime(path));
      // Then set the created & last accessed time...
      zipOutputStream.putNextEntry(zipEntry); com.google.common.io.Files.asByteSource(path.toFile()).copyTo(zipOutputStream); 
      zipOutputStream.closeEntry(); 

       

       

            Unassigned Unassigned
            lovexyn0827 lovexyn0827
            Votes:
            6 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: