Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haskell
Cabal
Commits
6ce9ca28
"README.md" did not exist on "57c8d1c2c8ceba6973a48d138d1bb018ec2988ae"
Commit
6ce9ca28
authored
11 years ago
by
Mikhail Glushenkov
Browse files
Options
Downloads
Patches
Plain Diff
getModTime: Convert Windows time to POSIX seconds.
Fixes #1538.
parent
1324deb2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cabal-install/Distribution/Client/Compat/Time.hs
+45
-26
45 additions, 26 deletions
cabal-install/Distribution/Client/Compat/Time.hs
with
45 additions
and
26 deletions
cabal-install/Distribution/Client/Compat/Time.hs
+
45
−
26
View file @
6ce9ca28
...
...
@@ -16,19 +16,24 @@ import System.Time (ClockTime(..), getClockTime
#
if
defined
mingw32_HOST_OS
import
Data.
Int
(
Int32
)
import
Data.
Word
(
Word
32
)
import
Foreign
(
Ptr
,
allocaBytes
,
peekByteOff
)
import
Foreign
.C.Types
(
CChar
)
import
Foreign.C.String
(
withCString
)
import
System.
IO.Error
(
mkIOError
,
doesNotExistErrorType
)
import
Data.
Bits
(
(
.|.
),
bitSize
,
unsafeShiftL
)
import
Data.
Int
(
Int
32
)
import
Data.Word
(
Word64
)
import
Foreign
(
allocaBytes
,
peekByteOff
)
import
System.IO.Error
(
mkIOError
,
doesNotExistErrorType
)
import
System.
Win32.Types
(
BOOL
,
DWORD
,
LPCTSTR
,
LPVOID
,
withTString
)
type
WIN32_FILE_ATTRIBUTE_DATA
=
Ptr
()
type
LPCSTR
=
Ptr
CChar
foreign
import
stdcall
"Windows.h GetFileAttributesExA"
c_getFileAttributesEx
::
LPCSTR
->
Int32
->
WIN32_FILE_ATTRIBUTE_DATA
->
IO
Bool
foreign
import
stdcall
"windows.h GetFileAttributesExW"
c_getFileAttributesEx
::
LPCTSTR
->
Int32
->
LPVOID
->
IO
BOOL
getFileAttributesEx
::
String
->
LPVOID
->
IO
BOOL
getFileAttributesEx
path
lpFileInformation
=
withTString
path
$
\
c_path
->
c_getFileAttributesEx
c_path
getFileExInfoStandard
lpFileInformation
getFileExInfoStandard
::
Int32
getFileExInfoStandard
=
0
size_WIN32_FILE_ATTRIBUTE_DATA
::
Int
size_WIN32_FILE_ATTRIBUTE_DATA
=
36
...
...
@@ -36,6 +41,9 @@ size_WIN32_FILE_ATTRIBUTE_DATA = 36
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwLowDateTime
::
Int
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwLowDateTime
=
20
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwHighDateTime
::
Int
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwHighDateTime
=
24
#
else
#
if
MIN_VERSION_base
(
4
,
5
,
0
)
...
...
@@ -60,21 +68,32 @@ getModTime :: FilePath -> IO EpochTime
#
if
defined
mingw32_HOST_OS
-- Directly against the Win32 API.
getModTime
path
=
withCString
path
$
\
file
->
allocaBytes
size_WIN32_FILE_ATTRIBUTE_DATA
$
\
info
->
do
res
<-
c_getFileAttributesEx
file
0
info
if
not
res
then
do
let
err
=
mkIOError
doesNotExistErrorType
"Distribution.Client.Compat.Time.getModTime"
Nothing
(
Just
path
)
ioError
err
else
do
dword
<-
peekByteOff
info
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwLowDateTime
-- TODO: Convert Windows seconds to POSIX seconds. ATM we don't care
-- since we only use the value for comparisons.
return
$!
fromIntegral
(
dword
::
Word32
)
getModTime
path
=
allocaBytes
size_WIN32_FILE_ATTRIBUTE_DATA
$
\
info
->
do
res
<-
getFileAttributesEx
path
info
if
not
res
then
do
let
err
=
mkIOError
doesNotExistErrorType
"Distribution.Client.Compat.Time.getModTime"
Nothing
(
Just
path
)
ioError
err
else
do
dwLow
<-
peekByteOff
info
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwLowDateTime
dwHigh
<-
peekByteOff
info
index_WIN32_FILE_ATTRIBUTE_DATA_ftLastWriteTime_dwHighDateTime
return
$!
windowsTimeToPOSIXSeconds
dwLow
dwHigh
where
windowsTimeToPOSIXSeconds
::
DWORD
->
DWORD
->
EpochTime
windowsTimeToPOSIXSeconds
dwLow
dwHigh
=
let
wINDOWS_TICK
=
10000000
sEC_TO_UNIX_EPOCH
=
11644473600
qwTime
=
(
fromIntegral
dwHigh
`
unsafeShiftL
`
bitSize
dwHigh
)
.|.
(
fromIntegral
dwLow
)
res
=
((
qwTime
::
Word64
)
`
div
`
wINDOWS_TICK
)
-
sEC_TO_UNIX_EPOCH
-- TODO: What if the result is not representable as POSIX seconds?
-- Probably fine to return garbage.
in
fromIntegral
res
#
else
-- Directly against the unix library.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment