Skip to content

import conditionalization in System.Posix.Files.Common is wrong

System/Posix/Files/Common.hsc imports Data.Int and Data.Ratio conditionally, to avoid "unused import" compiler warnings:

#if defined(HAVE_STRUCT_STAT_ST_CTIM) || \
    defined(HAVE_STRUCT_STAT_ST_MTIM) || \
    defined(HAVE_STRUCT_STAT_ST_ATIM) || \
    defined(HAVE_STRUCT_STAT_ST_ATIMESPEC) || \
    defined(HAVE_STRUCT_STAT_ST_MTIMESPEC) || \
    defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
import Data.Int
import Data.Ratio
#endif

but those modules are actually used in functions like

accessTimeHiRes (FileStatus stat) =
  unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
    sec  <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime
#ifdef HAVE_STRUCT_STAT_ST_ATIM
    nsec <- (#peek struct stat, st_atim.tv_nsec) stat_ptr :: IO (#type long)
    let frac = toInteger nsec % 10^(9::Int)
#elif HAVE_STRUCT_STAT_ST_ATIMESPEC
    nsec <- (#peek struct stat, st_atimespec.tv_nsec) stat_ptr :: IO (#type long)
    let frac = toInteger nsec % 10^(9::Int)
#elif HAVE_STRUCT_STAT_ST_ATIMENSEC
    nsec <- (#peek struct stat, st_atimensec) stat_ptr :: IO (#type long)
    let frac = toInteger nsec % 10^(9::Int)
#elif HAVE_STRUCT_STAT_ST_ATIME_N
    nsec <- (#peek struct stat, st_atime_n) stat_ptr :: IO (#type int)
    let frac = toInteger nsec % 10^(9::Int)
#elif HAVE_STRUCT_STAT_ST_UATIME
    usec <- (#peek struct stat, st_uatime) stat_ptr :: IO (#type int)
    let frac = toInteger usec % 10^(6::Int)
#else
    let frac = 0
#endif
    return $ fromRational $ toRational sec + frac

so there should be additional tests for defined(HAVE_STRUCT_STAT_ST_ATIMENSEC), defined(HAVE_STRUCT_STAT_ST_ATIME_N), ... (15 total).

Or, maybe there's a better alternative, since this is very long-winded and fragile...

This breaks the build on Android, which has st_atimensec.

Trac metadata
Trac field Value
Version 7.8.1-rc2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/unix
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information