mojira.dev
MC-271516

Time information of files in backups is lost

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();

 

 

Comments 2

Do you mean that the last modified date is reset to the current date and time for all backed up files?

I mean, the last modified time of the contents of backup archives, like .mca files are reset to the created time of the archive.

lovexyn0827

(Unassigned)

Confirmed

Platform

Normal

Save Data

1.20.6, 24w18a, 1.21 Pre-Release 2, 1.21

Retrieved