diff options
Diffstat (limited to 'Annex/Journal.hs')
-rw-r--r-- | Annex/Journal.hs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/Annex/Journal.hs b/Annex/Journal.hs index 2df5294ee..e68591ce2 100644 --- a/Annex/Journal.hs +++ b/Annex/Journal.hs @@ -9,6 +9,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE CPP #-} + module Annex.Journal where import System.IO.Binary @@ -64,26 +66,38 @@ journalDirty = not . null <$> getJournalFiles journalFile :: FilePath -> Git.Repo -> FilePath journalFile file repo = gitAnnexJournalDir repo </> concatMap mangle file where - mangle '/' = "_" - mangle '_' = "__" - mangle c = [c] + mangle c + | c == pathSeparator = "_" + | c == '_' = "__" + | otherwise = [c] {- Converts a journal file (relative to the journal dir) back to the - filename on the branch. -} fileJournal :: FilePath -> FilePath -fileJournal = replace "//" "_" . replace "_" "/" +fileJournal = replace [pathSeparator, pathSeparator] "_" . + replace "_" [pathSeparator] {- Runs an action that modifies the journal, using locking to avoid - contention with other git-annex processes. -} lockJournal :: Annex a -> Annex a lockJournal a = do - file <- fromRepo gitAnnexJournalLock - createAnnexDirectory $ takeDirectory file + lockfile <- fromRepo gitAnnexJournalLock + createAnnexDirectory $ takeDirectory lockfile mode <- annexFileMode - bracketIO (lock file mode) unlock a + bracketIO (lock lockfile mode) unlock a where - lock file mode = do - l <- noUmask mode $ createFile file mode + lock lockfile mode = do +#ifndef __WINDOWS__ + l <- noUmask mode $ createFile lockfile mode waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0) return l +#else + writeFile lockfile "" + return lockfile +#endif +#ifndef __WINDOWS__ unlock = closeFd +#else + unlock = removeFile +#endif + |