From 472f5c142b063053828358a3031a2ca09a373127 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 2 Aug 2022 10:45:00 -0400 Subject: [PATCH] Use createFile_NoRetry from win32 2.13.3.1 Sponsored-by: Tobias Ammann on Patreon --- Utility/LockFile/Windows.hs | 13 +++++++++++-- ...epare_for_Win32_not_export_c__95___entities.mdwn | 2 ++ ...ment_4_28e5593e0a58fb7d7a2a297fa63e8208._comment | 9 +++++++++ git-annex.cabal | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities/comment_4_28e5593e0a58fb7d7a2a297fa63e8208._comment diff --git a/Utility/LockFile/Windows.hs b/Utility/LockFile/Windows.hs index 08f5e80930..9ec34c9a79 100644 --- a/Utility/LockFile/Windows.hs +++ b/Utility/LockFile/Windows.hs @@ -1,11 +1,11 @@ {- Windows lock files - - - Copyright 2014,2021 Joey Hess + - Copyright 2014,2022 Joey Hess - - License: BSD-2-clause -} -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings, CPP #-} module Utility.LockFile.Windows ( lockShared, @@ -61,12 +61,21 @@ lockExclusive = openLock fILE_SHARE_NONE openLock :: ShareMode -> LockFile -> IO (Maybe LockHandle) openLock sharemode f = do f' <- convertToNativeNamespace f +#if MIN_VERSION_win32(2,13,3) + r <- tryNonAsync $ createFile_NoRetry f' gENERIC_READ sharemode + security_attributes oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL + (maybePtr Nothing) + return $ case r of + Left _ -> Nothing + Right h -> Just h +#else h <- withTString (fromRawFilePath f') $ \c_f -> c_CreateFile c_f gENERIC_READ sharemode security_attributes oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL (maybePtr Nothing) return $ if h == iNVALID_HANDLE_VALUE then Nothing else Just h +#endif where security_attributes = maybePtr Nothing diff --git a/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities.mdwn b/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities.mdwn index 73b2b454b3..9442fa50ac 100644 --- a/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities.mdwn +++ b/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities.mdwn @@ -53,3 +53,5 @@ using Windows LockFileEx, for instance the one by my compatriot: [[fixed|done]] --[[Joey]] diff --git a/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities/comment_4_28e5593e0a58fb7d7a2a297fa63e8208._comment b/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities/comment_4_28e5593e0a58fb7d7a2a297fa63e8208._comment new file mode 100644 index 0000000000..5365531c7f --- /dev/null +++ b/doc/todo/windows__58___prepare_for_Win32_not_export_c__95___entities/comment_4_28e5593e0a58fb7d7a2a297fa63e8208._comment @@ -0,0 +1,9 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 4""" + date="2022-08-02T14:43:47Z" + content=""" +The necessary change will be in win32 2.13.3.1, which should be released +in due course. And I've made a (so far untested) change to git-annex to +support that version. +"""]] diff --git a/git-annex.cabal b/git-annex.cabal index d27c0c4b62..261de5f638 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -402,7 +402,7 @@ Executable git-annex if (os(windows)) Build-Depends: - Win32 (>= 2.6.1.0 && < 2.12.0.0), + Win32 ((>= 2.6.1.0 && < 2.12.0.0) || >= 2.13.3.1), setenv, process (>= 1.6.2.0), silently (>= 1.2.5.1) -- 2.30.2