From 12d504e086d29686cc6dded398a082f7cd221c80 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Sat, 2 Dec 2023 13:37:23 +0800 Subject: [PATCH] #280: Round up mtimes for zip archives if before 1980 --- CHANGELOG.md | 4 ++++ src/path.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3363ba11..800db6dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ * Added: * When a path or URL fails to open, additional information is now logged. +* Fixed: + * When storing file modified times in zip archives, + if the year is too old for zip to support (i.e., before 1980), + Ludusavi will now round up to the earliest support date (1980-01-01). ## v0.21.0 (2023-08-22) diff --git a/src/path.rs b/src/path.rs index 951710ee..d9770afa 100644 --- a/src/path.rs +++ b/src/path.rs @@ -399,6 +399,14 @@ impl StrictPath { use chrono::{Datelike, Timelike}; let mtime: chrono::DateTime = self.get_mtime()?.into(); + + // Zip doesn't support years before 1980, + // and this is probably just a default Unix timestamp anyway, + // so we round up. + if mtime.year() < 1980 { + return Ok(zip::DateTime::default()); + } + let converted = zip::DateTime::from_date_and_time( mtime.year() as u16, mtime.month() as u8,