Skip to content

Commit

Permalink
readEntry: fix computation of modification time.
Browse files Browse the repository at this point in the history
It should be a UNIX time (seconds since UNIX epoch), but computed
relative to the *local* time zone, not UTC.

Closes #67.
  • Loading branch information
jgm committed Apr 5, 2024
1 parent c4f8de6 commit efe4423
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Codec/Archive/Zip.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ module Codec.Archive.Zip

import Data.Time.Calendar ( toGregorian, fromGregorian )
import Data.Time.Clock ( UTCTime(..) )
import Data.Time.LocalTime ( TimeZone(..), TimeOfDay(..), timeToTimeOfDay,
getTimeZone )
import Data.Time.Clock.POSIX ( posixSecondsToUTCTime, utcTimeToPOSIXSeconds )
import Data.Time.LocalTime ( TimeOfDay(..), timeToTimeOfDay )
import Data.Bits ( shiftL, shiftR, (.&.), (.|.), xor, testBit )
import Data.Binary
import Data.Binary.Get
Expand All @@ -85,7 +86,7 @@ import Text.Printf
import System.FilePath
import System.Directory
(doesDirectoryExist, getDirectoryContents,
createDirectoryIfMissing, getModificationTime)
createDirectoryIfMissing, getModificationTime,)
import Control.Monad ( when, unless, zipWithM_ )
import qualified Control.Exception as E
import System.IO ( stderr, hPutStrLn )
Expand Down Expand Up @@ -315,7 +316,11 @@ readEntry opts path = do
return B.empty
else
B.fromStrict <$> S.readFile path
modEpochTime <- (floor . utcTimeToPOSIXSeconds) <$> getModificationTime path
modTime <- getModificationTime path
tzone <- getTimeZone modTime
let modEpochTime = -- UNIX time computed relative to LOCAL time zone! (#67)
floor (utcTimeToPOSIXSeconds modTime) +
fromIntegral (timeZoneMinutes tzone * 60)
let entry = toEntry path' modEpochTime contents

entryE <-
Expand Down

0 comments on commit efe4423

Please sign in to comment.