git-annex now builds on Windows (doesn't work)
This commit is contained in:
parent
3a7eb68c1a
commit
3c7e30a295
52 changed files with 319 additions and 64 deletions
|
@ -24,8 +24,10 @@ module Annex.Branch (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
#ifndef mingw32_HOST_OS
|
#ifdef __ANDROID__
|
||||||
import System.Posix.Env
|
import System.Posix.Env (getEnv)
|
||||||
|
#else
|
||||||
|
import System.Environment (getEnvironment)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -290,12 +292,14 @@ withIndex' bootstrapping a = do
|
||||||
f <- fromRepo gitAnnexIndex
|
f <- fromRepo gitAnnexIndex
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
{- Work around for weird getEnvironment breakage on Android. See
|
{- This should not be necessary on Android, but there is some
|
||||||
|
- weird getEnvironment breakage. See
|
||||||
- https://github.com/neurocyte/ghc-android/issues/7
|
- https://github.com/neurocyte/ghc-android/issues/7
|
||||||
- Instead, use getEnv to get some key environment variables that
|
- Use getEnv to get some key environment variables that
|
||||||
- git expects to have. -}
|
- git expects to have. -}
|
||||||
let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME"
|
let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME"
|
||||||
let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$> getEnv k
|
let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$>
|
||||||
|
catchMaybeIO (getEnv k)
|
||||||
e <- liftIO $ catMaybes <$> forM keyenv getEnvPair
|
e <- liftIO $ catMaybes <$> forM keyenv getEnvPair
|
||||||
#else
|
#else
|
||||||
e <- liftIO getEnvironment
|
e <- liftIO getEnvironment
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Annex.Content (
|
module Annex.Content (
|
||||||
inAnnex,
|
inAnnex,
|
||||||
inAnnexSafe,
|
inAnnexSafe,
|
||||||
|
@ -31,6 +33,7 @@ module Annex.Content (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import System.IO.Unsafe (unsafeInterleaveIO)
|
import System.IO.Unsafe (unsafeInterleaveIO)
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
|
@ -84,14 +87,22 @@ inAnnexSafe = inAnnex' (fromMaybe False) (Just False) go
|
||||||
where
|
where
|
||||||
go f = liftIO $ openforlock f >>= check
|
go f = liftIO $ openforlock f >>= check
|
||||||
openforlock f = catchMaybeIO $
|
openforlock f = catchMaybeIO $
|
||||||
|
#ifndef __WINDOWS__
|
||||||
openFd f ReadOnly Nothing defaultFileFlags
|
openFd f ReadOnly Nothing defaultFileFlags
|
||||||
|
#else
|
||||||
|
return ()
|
||||||
|
#endif
|
||||||
check Nothing = return is_missing
|
check Nothing = return is_missing
|
||||||
check (Just h) = do
|
check (Just h) = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
v <- getLock h (ReadLock, AbsoluteSeek, 0, 0)
|
v <- getLock h (ReadLock, AbsoluteSeek, 0, 0)
|
||||||
closeFd h
|
closeFd h
|
||||||
return $ case v of
|
return $ case v of
|
||||||
Just _ -> is_locked
|
Just _ -> is_locked
|
||||||
Nothing -> is_unlocked
|
Nothing -> is_unlocked
|
||||||
|
#else
|
||||||
|
return is_unlocked
|
||||||
|
#endif
|
||||||
is_locked = Nothing
|
is_locked = Nothing
|
||||||
is_unlocked = Just True
|
is_unlocked = Just True
|
||||||
is_missing = Just False
|
is_missing = Just False
|
||||||
|
@ -100,6 +111,9 @@ inAnnexSafe = inAnnex' (fromMaybe False) (Just False) go
|
||||||
- it. (If the content is not present, no locking is done.) -}
|
- it. (If the content is not present, no locking is done.) -}
|
||||||
lockContent :: Key -> Annex a -> Annex a
|
lockContent :: Key -> Annex a -> Annex a
|
||||||
lockContent key a = do
|
lockContent key a = do
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
a
|
||||||
|
#else
|
||||||
file <- calcRepo $ gitAnnexLocation key
|
file <- calcRepo $ gitAnnexLocation key
|
||||||
bracketIO (openforlock file >>= lock) unlock a
|
bracketIO (openforlock file >>= lock) unlock a
|
||||||
where
|
where
|
||||||
|
@ -121,6 +135,7 @@ lockContent key a = do
|
||||||
Right _ -> return $ Just fd
|
Right _ -> return $ Just fd
|
||||||
unlock Nothing = noop
|
unlock Nothing = noop
|
||||||
unlock (Just l) = closeFd l
|
unlock (Just l) = closeFd l
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Runs an action, passing it a temporary filename to get,
|
{- Runs an action, passing it a temporary filename to get,
|
||||||
- and if the action succeeds, moves the temp file into
|
- and if the action succeeds, moves the temp file into
|
||||||
|
|
2
Annex/Content/Direct.hs
Normal file → Executable file
2
Annex/Content/Direct.hs
Normal file → Executable file
|
@ -33,6 +33,8 @@ import Utility.TempFile
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
import Utility.InodeCache
|
import Utility.InodeCache
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
{- Absolute FilePaths of Files in the tree that are associated with a key. -}
|
{- Absolute FilePaths of Files in the tree that are associated with a key. -}
|
||||||
associatedFiles :: Key -> Annex [FilePath]
|
associatedFiles :: Key -> Annex [FilePath]
|
||||||
associatedFiles key = do
|
associatedFiles key = do
|
||||||
|
|
2
Annex/Direct.hs
Normal file → Executable file
2
Annex/Direct.hs
Normal file → Executable file
|
@ -27,6 +27,8 @@ import Utility.InodeCache
|
||||||
import Utility.CopyFile
|
import Utility.CopyFile
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
{- Uses git ls-files to find files that need to be committed, and stages
|
{- Uses git ls-files to find files that need to be committed, and stages
|
||||||
- them into the index. Returns True if some changes were staged. -}
|
- them into the index. Returns True if some changes were staged. -}
|
||||||
stageDirect :: Annex Bool
|
stageDirect :: Annex Bool
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
module Annex.Environment where
|
module Annex.Environment where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
#ifndef __WINDOWS__
|
||||||
import Utility.UserInfo
|
import Utility.UserInfo
|
||||||
|
#endif
|
||||||
import qualified Git.Config
|
import qualified Git.Config
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Env
|
import System.Posix.Env
|
||||||
#endif
|
#endif
|
||||||
import Network.BSD
|
import Network.BSD
|
||||||
|
@ -28,7 +30,10 @@ checkEnvironment = do
|
||||||
liftIO checkEnvironmentIO
|
liftIO checkEnvironmentIO
|
||||||
|
|
||||||
checkEnvironmentIO :: IO ()
|
checkEnvironmentIO :: IO ()
|
||||||
checkEnvironmentIO = do
|
checkEnvironmentIO =
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
noop
|
||||||
|
#else
|
||||||
whenM (null <$> myUserGecos) $ do
|
whenM (null <$> myUserGecos) $ do
|
||||||
username <- myUserName
|
username <- myUserName
|
||||||
ensureEnv "GIT_AUTHOR_NAME" username
|
ensureEnv "GIT_AUTHOR_NAME" username
|
||||||
|
@ -42,3 +47,4 @@ checkEnvironmentIO = do
|
||||||
-- in runshell instead.
|
-- in runshell instead.
|
||||||
ensureEnv _ _ = noop
|
ensureEnv _ _ = noop
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
22
Annex/Journal.hs
Normal file → Executable file
22
Annex/Journal.hs
Normal file → Executable file
|
@ -9,6 +9,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Annex.Journal where
|
module Annex.Journal where
|
||||||
|
|
||||||
import System.IO.Binary
|
import System.IO.Binary
|
||||||
|
@ -77,13 +79,23 @@ fileJournal = replace "//" "_" . replace "_" "/"
|
||||||
- contention with other git-annex processes. -}
|
- contention with other git-annex processes. -}
|
||||||
lockJournal :: Annex a -> Annex a
|
lockJournal :: Annex a -> Annex a
|
||||||
lockJournal a = do
|
lockJournal a = do
|
||||||
file <- fromRepo gitAnnexJournalLock
|
lockfile <- fromRepo gitAnnexJournalLock
|
||||||
createAnnexDirectory $ takeDirectory file
|
createAnnexDirectory $ takeDirectory lockfile
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
bracketIO (lock file mode) unlock a
|
bracketIO (lock lockfile mode) unlock a
|
||||||
where
|
where
|
||||||
lock file mode = do
|
lock lockfile mode = do
|
||||||
l <- noUmask mode $ createFile file mode
|
#ifndef __WINDOWS__
|
||||||
|
l <- noUmask mode $ createFile lockfile mode
|
||||||
waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
|
waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
|
||||||
return l
|
return l
|
||||||
|
#else
|
||||||
|
writeFile lockfile ""
|
||||||
|
return lockfile
|
||||||
|
#endif
|
||||||
|
#ifndef __WINDOWS__
|
||||||
unlock = closeFd
|
unlock = closeFd
|
||||||
|
#else
|
||||||
|
unlock = removeFile
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
2
Annex/Link.hs
Normal file → Executable file
2
Annex/Link.hs
Normal file → Executable file
|
@ -19,6 +19,8 @@ import qualified Git.UpdateIndex
|
||||||
import qualified Annex.Queue
|
import qualified Annex.Queue
|
||||||
import Git.Types
|
import Git.Types
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
type LinkTarget = String
|
type LinkTarget = String
|
||||||
|
|
||||||
{- Checks if a file is a link to a key. -}
|
{- Checks if a file is a link to a key. -}
|
||||||
|
|
9
Annex/LockPool.hs
Normal file → Executable file
9
Annex/LockPool.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Annex.LockPool where
|
module Annex.LockPool where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
@ -20,17 +22,24 @@ lockFile file = go =<< fromPool file
|
||||||
where
|
where
|
||||||
go (Just _) = noop -- already locked
|
go (Just _) = noop -- already locked
|
||||||
go Nothing = do
|
go Nothing = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
fd <- liftIO $ noUmask mode $
|
fd <- liftIO $ noUmask mode $
|
||||||
openFd file ReadOnly (Just mode) defaultFileFlags
|
openFd file ReadOnly (Just mode) defaultFileFlags
|
||||||
liftIO $ waitToSetLock fd (ReadLock, AbsoluteSeek, 0, 0)
|
liftIO $ waitToSetLock fd (ReadLock, AbsoluteSeek, 0, 0)
|
||||||
|
#else
|
||||||
|
liftIO $ writeFile file ""
|
||||||
|
let fd = 0
|
||||||
|
#endif
|
||||||
changePool $ M.insert file fd
|
changePool $ M.insert file fd
|
||||||
|
|
||||||
unlockFile :: FilePath -> Annex ()
|
unlockFile :: FilePath -> Annex ()
|
||||||
unlockFile file = maybe noop go =<< fromPool file
|
unlockFile file = maybe noop go =<< fromPool file
|
||||||
where
|
where
|
||||||
go fd = do
|
go fd = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
liftIO $ closeFd fd
|
liftIO $ closeFd fd
|
||||||
|
#endif
|
||||||
changePool $ M.delete file
|
changePool $ M.delete file
|
||||||
|
|
||||||
getPool :: Annex (M.Map FilePath Fd)
|
getPool :: Annex (M.Map FilePath Fd)
|
||||||
|
|
1
Annex/Perms.hs
Normal file → Executable file
1
Annex/Perms.hs
Normal file → Executable file
|
@ -22,6 +22,7 @@ import qualified Annex
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
withShared :: (SharedRepository -> Annex a) -> Annex a
|
withShared :: (SharedRepository -> Annex a) -> Annex a
|
||||||
withShared a = maybe startup a =<< Annex.getState Annex.shared
|
withShared a = maybe startup a =<< Annex.getState Annex.shared
|
||||||
|
|
10
Annex/Ssh.hs
10
Annex/Ssh.hs
|
@ -14,7 +14,7 @@ module Annex.Ssh (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Env
|
import System.Posix.Env
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,7 +78,11 @@ sshCacheDir
|
||||||
)
|
)
|
||||||
| otherwise = return Nothing
|
| otherwise = return Nothing
|
||||||
where
|
where
|
||||||
|
#ifndef __WINDOWS__
|
||||||
gettmpdir = liftIO $ getEnv "GIT_ANNEX_TMP_DIR"
|
gettmpdir = liftIO $ getEnv "GIT_ANNEX_TMP_DIR"
|
||||||
|
#else
|
||||||
|
gettmpdir = return Nothing
|
||||||
|
#endif
|
||||||
usetmpdir tmpdir = liftIO $ catchMaybeIO $ do
|
usetmpdir tmpdir = liftIO $ catchMaybeIO $ do
|
||||||
createDirectoryIfMissing True tmpdir
|
createDirectoryIfMissing True tmpdir
|
||||||
return tmpdir
|
return tmpdir
|
||||||
|
@ -97,6 +101,7 @@ sshCleanup = go =<< sshCacheDir
|
||||||
liftIO (catchDefaultIO [] $ dirContents dir)
|
liftIO (catchDefaultIO [] $ dirContents dir)
|
||||||
forM_ sockets cleanup
|
forM_ sockets cleanup
|
||||||
cleanup socketfile = do
|
cleanup socketfile = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
-- Drop any shared lock we have, and take an
|
-- Drop any shared lock we have, and take an
|
||||||
-- exclusive lock, without blocking. If the lock
|
-- exclusive lock, without blocking. If the lock
|
||||||
-- succeeds, nothing is using this ssh, and it can
|
-- succeeds, nothing is using this ssh, and it can
|
||||||
|
@ -112,6 +117,9 @@ sshCleanup = go =<< sshCacheDir
|
||||||
Left _ -> noop
|
Left _ -> noop
|
||||||
Right _ -> stopssh socketfile
|
Right _ -> stopssh socketfile
|
||||||
liftIO $ closeFd fd
|
liftIO $ closeFd fd
|
||||||
|
#else
|
||||||
|
stopssh socketfile
|
||||||
|
#endif
|
||||||
stopssh socketfile = do
|
stopssh socketfile = do
|
||||||
let (host, port) = socket2hostport socketfile
|
let (host, port) = socket2hostport socketfile
|
||||||
(_, params) <- sshInfo (host, port)
|
(_, params) <- sshInfo (host, port)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Annex.Version where
|
module Annex.Version where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -23,7 +25,11 @@ supportedVersions :: [Version]
|
||||||
supportedVersions = [defaultVersion, directModeVersion]
|
supportedVersions = [defaultVersion, directModeVersion]
|
||||||
|
|
||||||
upgradableVersions :: [Version]
|
upgradableVersions :: [Version]
|
||||||
|
#ifndef __WINDOWS__
|
||||||
upgradableVersions = ["0", "1", "2"]
|
upgradableVersions = ["0", "1", "2"]
|
||||||
|
#else
|
||||||
|
upgradableVersions = ["2"]
|
||||||
|
#endif
|
||||||
|
|
||||||
versionField :: ConfigKey
|
versionField :: ConfigKey
|
||||||
versionField = annexConfig "version"
|
versionField = annexConfig "version"
|
||||||
|
|
1
Backend/SHA.hs
Normal file → Executable file
1
Backend/SHA.hs
Normal file → Executable file
|
@ -18,6 +18,7 @@ import qualified Build.SysConfig as SysConfig
|
||||||
import Data.Digest.Pure.SHA
|
import Data.Digest.Pure.SHA
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
type SHASize = Int
|
type SHASize = Int
|
||||||
|
|
||||||
|
|
2
Backend/WORM.hs
Normal file → Executable file
2
Backend/WORM.hs
Normal file → Executable file
|
@ -12,6 +12,8 @@ import Types.Backend
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Types.KeySource
|
import Types.KeySource
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
backends :: [Backend]
|
backends :: [Backend]
|
||||||
backends = [backend]
|
backends = [backend]
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import qualified Control.Exception as E
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Control.Exception (throw)
|
import Control.Exception (throw)
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Signals
|
import System.Posix.Signals
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -118,7 +118,9 @@ tryRun' errnum state cmd (a:as) = do
|
||||||
{- Actions to perform each time ran. -}
|
{- Actions to perform each time ran. -}
|
||||||
startup :: Annex Bool
|
startup :: Annex Bool
|
||||||
startup = liftIO $ do
|
startup = liftIO $ do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
void $ installHandler sigINT Default Nothing
|
void $ installHandler sigINT Default Nothing
|
||||||
|
#endif
|
||||||
return True
|
return True
|
||||||
|
|
||||||
{- Cleanup actions. -}
|
{- Cleanup actions. -}
|
||||||
|
|
2
Command/Add.hs
Normal file → Executable file
2
Command/Add.hs
Normal file → Executable file
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
module Command.Add where
|
module Command.Add where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Annex.Exception
|
import Annex.Exception
|
||||||
import Command
|
import Command
|
||||||
|
|
2
Command/Fix.hs
Normal file → Executable file
2
Command/Fix.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.Fix where
|
module Command.Fix where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex.Queue
|
import qualified Annex.Queue
|
||||||
|
|
2
Command/FromKey.hs
Normal file → Executable file
2
Command/FromKey.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.FromKey where
|
module Command.FromKey where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex.Queue
|
import qualified Annex.Queue
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
module Command.Fsck where
|
module Command.Fsck where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
@ -30,8 +32,10 @@ import qualified Option
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Utility.HumanTime
|
import Utility.HumanTime
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Process (getProcessID)
|
import System.Posix.Process (getProcessID)
|
||||||
|
#else
|
||||||
|
import System.Random (getStdRandom, random)
|
||||||
#endif
|
#endif
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
import Data.Time
|
import Data.Time
|
||||||
|
@ -142,10 +146,14 @@ performRemote key file backend numcopies remote =
|
||||||
, checkKeyNumCopies key file numcopies
|
, checkKeyNumCopies key file numcopies
|
||||||
]
|
]
|
||||||
withtmp a = do
|
withtmp a = do
|
||||||
pid <- liftIO getProcessID
|
#ifndef __WINDOWS__
|
||||||
|
v <- liftIO getProcessID
|
||||||
|
#else
|
||||||
|
v <- liftIO (getStdRandom random :: IO Int)
|
||||||
|
#endif
|
||||||
t <- fromRepo gitAnnexTmpDir
|
t <- fromRepo gitAnnexTmpDir
|
||||||
createAnnexDirectory t
|
createAnnexDirectory t
|
||||||
let tmp = t </> "fsck" ++ show pid ++ "." ++ keyFile key
|
let tmp = t </> "fsck" ++ show v ++ "." ++ keyFile key
|
||||||
let cleanup = liftIO $ catchIO (removeFile tmp) (const noop)
|
let cleanup = liftIO $ catchIO (removeFile tmp) (const noop)
|
||||||
cleanup
|
cleanup
|
||||||
cleanup `after` a tmp
|
cleanup `after` a tmp
|
||||||
|
@ -453,7 +461,9 @@ recordFsckTime key = do
|
||||||
parent <- parentDir <$> calcRepo (gitAnnexLocation key)
|
parent <- parentDir <$> calcRepo (gitAnnexLocation key)
|
||||||
liftIO $ void $ tryIO $ do
|
liftIO $ void $ tryIO $ do
|
||||||
touchFile parent
|
touchFile parent
|
||||||
|
#ifndef __WINDOWS__
|
||||||
setSticky parent
|
setSticky parent
|
||||||
|
#endif
|
||||||
|
|
||||||
getFsckTime :: Key -> Annex (Maybe EpochTime)
|
getFsckTime :: Key -> Annex (Maybe EpochTime)
|
||||||
getFsckTime key = do
|
getFsckTime key = do
|
||||||
|
|
2
Command/Import.hs
Normal file → Executable file
2
Command/Import.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.Import where
|
module Command.Import where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
2
Command/Indirect.hs
Normal file → Executable file
2
Command/Indirect.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.Indirect where
|
module Command.Indirect where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
|
2
Command/ReKey.hs
Normal file → Executable file
2
Command/ReKey.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.ReKey where
|
module Command.ReKey where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
2
Command/RecvKey.hs
Normal file → Executable file
2
Command/RecvKey.hs
Normal file → Executable file
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Command.RecvKey where
|
module Command.RecvKey where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import CmdLine
|
import CmdLine
|
||||||
|
|
1
Command/Status.hs
Normal file → Executable file
1
Command/Status.hs
Normal file → Executable file
|
@ -13,6 +13,7 @@ import "mtl" Control.Monad.State.Strict
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Text.JSON
|
import Text.JSON
|
||||||
import Data.Tuple
|
import Data.Tuple
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Types.Backend as B
|
import qualified Types.Backend as B
|
||||||
|
|
2
Command/TransferKeys.hs
Normal file → Executable file
2
Command/TransferKeys.hs
Normal file → Executable file
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
module Command.TransferKeys where
|
module Command.TransferKeys where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Command
|
import Command
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
|
|
6
Command/Unannex.hs
Normal file → Executable file
6
Command/Unannex.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Command.Unannex where
|
module Command.Unannex where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -58,6 +60,9 @@ cleanup file key = do
|
||||||
|
|
||||||
return True
|
return True
|
||||||
where
|
where
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
goFast = go
|
||||||
|
#else
|
||||||
goFast = do
|
goFast = do
|
||||||
-- fast mode: hard link to content in annex
|
-- fast mode: hard link to content in annex
|
||||||
src <- calcRepo $ gitAnnexLocation key
|
src <- calcRepo $ gitAnnexLocation key
|
||||||
|
@ -66,6 +71,7 @@ cleanup file key = do
|
||||||
( thawContent file
|
( thawContent file
|
||||||
, go
|
, go
|
||||||
)
|
)
|
||||||
|
#endif
|
||||||
go = do
|
go = do
|
||||||
fromAnnex key file
|
fromAnnex key file
|
||||||
logStatus key InfoMissing
|
logStatus key InfoMissing
|
||||||
|
|
4
Creds.hs
4
Creds.hs
|
@ -109,12 +109,16 @@ getEnvCredPair storage = liftM2 (,)
|
||||||
|
|
||||||
{- Stores a CredPair in the environment. -}
|
{- Stores a CredPair in the environment. -}
|
||||||
setEnvCredPair :: CredPair -> CredPairStorage -> IO ()
|
setEnvCredPair :: CredPair -> CredPairStorage -> IO ()
|
||||||
|
#ifndef __WINDOWS__
|
||||||
setEnvCredPair (l, p) storage = do
|
setEnvCredPair (l, p) storage = do
|
||||||
set uenv l
|
set uenv l
|
||||||
set penv p
|
set penv p
|
||||||
where
|
where
|
||||||
(uenv, penv) = credPairEnvironment storage
|
(uenv, penv) = credPairEnvironment storage
|
||||||
set var val = setEnv var val True
|
set var val = setEnv var val True
|
||||||
|
#else
|
||||||
|
setEnvCredPair _ _ = error "setEnvCredPair TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
writeCacheCredPair :: CredPair -> CredPairStorage -> Annex ()
|
writeCacheCredPair :: CredPair -> CredPairStorage -> Annex ()
|
||||||
writeCacheCredPair credpair storage =
|
writeCacheCredPair credpair storage =
|
||||||
|
|
2
Git.hs
2
Git.hs
|
@ -32,7 +32,7 @@ module Git (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Network.URI (uriPath, uriScheme, unEscapeString)
|
import Network.URI (uriPath, uriScheme, unEscapeString)
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
0
Git/Config.hs
Normal file → Executable file
0
Git/Config.hs
Normal file → Executable file
|
@ -23,7 +23,7 @@ module Git.Construct (
|
||||||
checkForRepo,
|
checkForRepo,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.User
|
import System.Posix.User
|
||||||
#endif
|
#endif
|
||||||
import qualified Data.Map as M hiding (map, split)
|
import qualified Data.Map as M hiding (map, split)
|
||||||
|
@ -196,6 +196,9 @@ repoAbsPath d = do
|
||||||
return $ h </> d'
|
return $ h </> d'
|
||||||
|
|
||||||
expandTilde :: FilePath -> IO FilePath
|
expandTilde :: FilePath -> IO FilePath
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
expandTilde = return
|
||||||
|
#else
|
||||||
expandTilde = expandt True
|
expandTilde = expandt True
|
||||||
where
|
where
|
||||||
expandt _ [] = return ""
|
expandt _ [] = return ""
|
||||||
|
@ -216,6 +219,7 @@ expandTilde = expandt True
|
||||||
findname n (c:cs)
|
findname n (c:cs)
|
||||||
| c == '/' = (n, cs)
|
| c == '/' = (n, cs)
|
||||||
| otherwise = findname (n++[c]) cs
|
| otherwise = findname (n++[c]) cs
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Checks if a git repository exists in a directory. Does not find
|
{- Checks if a git repository exists in a directory. Does not find
|
||||||
- git repositories in parent directories. -}
|
- git repositories in parent directories. -}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
module Git.CurrentRepo where
|
module Git.CurrentRepo where
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Directory (changeWorkingDirectory)
|
import System.Posix.Directory (changeWorkingDirectory)
|
||||||
import System.Posix.Env (getEnv, unsetEnv)
|
import System.Posix.Env (getEnv, unsetEnv)
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,18 +39,24 @@ get = do
|
||||||
case wt of
|
case wt of
|
||||||
Nothing -> return r
|
Nothing -> return r
|
||||||
Just d -> do
|
Just d -> do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
unless (d `dirContains` cwd) $
|
unless (d `dirContains` cwd) $
|
||||||
changeWorkingDirectory d
|
changeWorkingDirectory d
|
||||||
|
#endif
|
||||||
return $ addworktree wt r
|
return $ addworktree wt r
|
||||||
where
|
where
|
||||||
pathenv s = do
|
pathenv s = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
v <- getEnv s
|
v <- getEnv s
|
||||||
case v of
|
case v of
|
||||||
Just d -> do
|
Just d -> do
|
||||||
unsetEnv s
|
unsetEnv s
|
||||||
Just <$> absPath d
|
Just <$> absPath d
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
|
#else
|
||||||
|
return Nothing
|
||||||
|
#endif
|
||||||
|
|
||||||
configure Nothing (Just r) = Git.Config.read r
|
configure Nothing (Just r) = Git.Config.read r
|
||||||
configure (Just d) _ = do
|
configure (Just d) _ = do
|
||||||
|
|
8
GitAnnex.hs
Normal file → Executable file
8
GitAnnex.hs
Normal file → Executable file
|
@ -23,7 +23,9 @@ import qualified Command.Get
|
||||||
import qualified Command.FromKey
|
import qualified Command.FromKey
|
||||||
import qualified Command.DropKey
|
import qualified Command.DropKey
|
||||||
import qualified Command.TransferKey
|
import qualified Command.TransferKey
|
||||||
|
#ifndef __WINDOWS__
|
||||||
import qualified Command.TransferKeys
|
import qualified Command.TransferKeys
|
||||||
|
#endif
|
||||||
import qualified Command.ReKey
|
import qualified Command.ReKey
|
||||||
import qualified Command.Reinject
|
import qualified Command.Reinject
|
||||||
import qualified Command.Fix
|
import qualified Command.Fix
|
||||||
|
@ -73,8 +75,10 @@ import qualified Command.XMPPGit
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef WITH_TESTSUITE
|
||||||
|
#ifndef __WINDOWS__
|
||||||
import qualified Command.Test
|
import qualified Command.Test
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
cmds :: [Command]
|
cmds :: [Command]
|
||||||
cmds = concat
|
cmds = concat
|
||||||
|
@ -107,7 +111,9 @@ cmds = concat
|
||||||
, Command.FromKey.def
|
, Command.FromKey.def
|
||||||
, Command.DropKey.def
|
, Command.DropKey.def
|
||||||
, Command.TransferKey.def
|
, Command.TransferKey.def
|
||||||
|
#ifndef __WINDOWS__
|
||||||
, Command.TransferKeys.def
|
, Command.TransferKeys.def
|
||||||
|
#endif
|
||||||
, Command.ReKey.def
|
, Command.ReKey.def
|
||||||
, Command.Fix.def
|
, Command.Fix.def
|
||||||
, Command.Fsck.def
|
, Command.Fsck.def
|
||||||
|
@ -137,7 +143,9 @@ cmds = concat
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef WITH_TESTSUITE
|
||||||
|
#ifndef __WINDOWS__
|
||||||
, Command.Test.def
|
, Command.Test.def
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,9 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
|
|
||||||
module GitAnnexShell where
|
module GitAnnexShell where
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
import System.Environment
|
||||||
import System.Posix.Env
|
|
||||||
#endif
|
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -149,7 +145,7 @@ checkNotReadOnly cmd
|
||||||
|
|
||||||
checkDirectory :: Maybe FilePath -> IO ()
|
checkDirectory :: Maybe FilePath -> IO ()
|
||||||
checkDirectory mdir = do
|
checkDirectory mdir = do
|
||||||
v <- getEnv "GIT_ANNEX_SHELL_DIRECTORY"
|
v <- catchMaybeIO $ getEnv "GIT_ANNEX_SHELL_DIRECTORY"
|
||||||
case (v, mdir) of
|
case (v, mdir) of
|
||||||
(Nothing, _) -> noop
|
(Nothing, _) -> noop
|
||||||
(Just d, Nothing) -> req d Nothing
|
(Just d, Nothing) -> req d Nothing
|
||||||
|
@ -179,7 +175,7 @@ checkDirectory mdir = do
|
||||||
|
|
||||||
checkEnv :: String -> IO ()
|
checkEnv :: String -> IO ()
|
||||||
checkEnv var = do
|
checkEnv var = do
|
||||||
v <- getEnv var
|
v <- catchMaybeIO $ getEnv var
|
||||||
case v of
|
case v of
|
||||||
Nothing -> noop
|
Nothing -> noop
|
||||||
Just "" -> noop
|
Just "" -> noop
|
||||||
|
|
16
Init.hs
Normal file → Executable file
16
Init.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Init (
|
module Init (
|
||||||
ensureInitialized,
|
ensureInitialized,
|
||||||
isInitialized,
|
isInitialized,
|
||||||
|
@ -34,11 +36,15 @@ import Backend
|
||||||
genDescription :: Maybe String -> Annex String
|
genDescription :: Maybe String -> Annex String
|
||||||
genDescription (Just d) = return d
|
genDescription (Just d) = return d
|
||||||
genDescription Nothing = do
|
genDescription Nothing = do
|
||||||
|
reldir <- liftIO . relHome =<< fromRepo Git.repoPath
|
||||||
hostname <- fromMaybe "" <$> liftIO getHostname
|
hostname <- fromMaybe "" <$> liftIO getHostname
|
||||||
|
#ifndef __WINDOWS__
|
||||||
let at = if null hostname then "" else "@"
|
let at = if null hostname then "" else "@"
|
||||||
username <- liftIO myUserName
|
username <- liftIO myUserName
|
||||||
reldir <- liftIO . relHome =<< fromRepo Git.repoPath
|
|
||||||
return $ concat [username, at, hostname, ":", reldir]
|
return $ concat [username, at, hostname, ":", reldir]
|
||||||
|
#else
|
||||||
|
return $ concat [hostname, ":", reldir]
|
||||||
|
#endif
|
||||||
|
|
||||||
initialize :: Maybe String -> Annex ()
|
initialize :: Maybe String -> Annex ()
|
||||||
initialize mdescription = do
|
initialize mdescription = do
|
||||||
|
@ -113,6 +119,9 @@ preCommitScript = unlines
|
||||||
|
|
||||||
probeCrippledFileSystem :: Annex Bool
|
probeCrippledFileSystem :: Annex Bool
|
||||||
probeCrippledFileSystem = do
|
probeCrippledFileSystem = do
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
return True
|
||||||
|
#else
|
||||||
tmp <- fromRepo gitAnnexTmpDir
|
tmp <- fromRepo gitAnnexTmpDir
|
||||||
let f = tmp </> "gaprobe"
|
let f = tmp </> "gaprobe"
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
|
@ -132,6 +141,7 @@ probeCrippledFileSystem = do
|
||||||
preventWrite f
|
preventWrite f
|
||||||
allowWrite f
|
allowWrite f
|
||||||
return True
|
return True
|
||||||
|
#endif
|
||||||
|
|
||||||
checkCrippledFileSystem :: Annex ()
|
checkCrippledFileSystem :: Annex ()
|
||||||
checkCrippledFileSystem = whenM probeCrippledFileSystem $ do
|
checkCrippledFileSystem = whenM probeCrippledFileSystem $ do
|
||||||
|
@ -149,6 +159,9 @@ checkCrippledFileSystem = whenM probeCrippledFileSystem $ do
|
||||||
|
|
||||||
probeFifoSupport :: Annex Bool
|
probeFifoSupport :: Annex Bool
|
||||||
probeFifoSupport = do
|
probeFifoSupport = do
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
return False
|
||||||
|
#else
|
||||||
tmp <- fromRepo gitAnnexTmpDir
|
tmp <- fromRepo gitAnnexTmpDir
|
||||||
let f = tmp </> "gaprobe"
|
let f = tmp </> "gaprobe"
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
|
@ -159,6 +172,7 @@ probeFifoSupport = do
|
||||||
getFileStatus f
|
getFileStatus f
|
||||||
nukeFile f
|
nukeFile f
|
||||||
return $ either (const False) isNamedPipe ms
|
return $ either (const False) isNamedPipe ms
|
||||||
|
#endif
|
||||||
|
|
||||||
checkFifoSupport :: Annex ()
|
checkFifoSupport :: Annex ()
|
||||||
checkFifoSupport = unlessM probeFifoSupport $ do
|
checkFifoSupport = unlessM probeFifoSupport $ do
|
||||||
|
|
1
Limit.hs
Normal file → Executable file
1
Limit.hs
Normal file → Executable file
|
@ -19,6 +19,7 @@ import Text.Regex.TDFA.String
|
||||||
#else
|
#else
|
||||||
import System.Path.WildMatch
|
import System.Path.WildMatch
|
||||||
#endif
|
#endif
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
21
Logs/Transfer.hs
Normal file → Executable file
21
Logs/Transfer.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Logs.Transfer where
|
module Logs.Transfer where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -18,6 +20,7 @@ import Utility.Percentage
|
||||||
import Utility.QuickCheck
|
import Utility.QuickCheck
|
||||||
|
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
|
import System.PosixCompat.Files
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
import Data.Time
|
import Data.Time
|
||||||
|
@ -122,6 +125,7 @@ runTransfer t file shouldretry a = do
|
||||||
return ok
|
return ok
|
||||||
where
|
where
|
||||||
prep tfile mode info = do
|
prep tfile mode info = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
mfd <- catchMaybeIO $
|
mfd <- catchMaybeIO $
|
||||||
openFd (transferLockFile tfile) ReadWrite (Just mode)
|
openFd (transferLockFile tfile) ReadWrite (Just mode)
|
||||||
defaultFileFlags { trunc = True }
|
defaultFileFlags { trunc = True }
|
||||||
|
@ -134,11 +138,18 @@ runTransfer t file shouldretry a = do
|
||||||
error "transfer already in progress"
|
error "transfer already in progress"
|
||||||
void $ tryIO $ writeTransferInfoFile info tfile
|
void $ tryIO $ writeTransferInfoFile info tfile
|
||||||
return mfd
|
return mfd
|
||||||
|
#else
|
||||||
|
catchMaybeIO $ do
|
||||||
|
writeFile (transferLockFile tfile) ""
|
||||||
|
writeTransferInfoFile info tfile
|
||||||
|
#endif
|
||||||
cleanup _ Nothing = noop
|
cleanup _ Nothing = noop
|
||||||
cleanup tfile (Just fd) = do
|
cleanup tfile (Just fd) = do
|
||||||
void $ tryIO $ removeFile tfile
|
void $ tryIO $ removeFile tfile
|
||||||
void $ tryIO $ removeFile $ transferLockFile tfile
|
void $ tryIO $ removeFile $ transferLockFile tfile
|
||||||
|
#ifndef __WINDOWS__
|
||||||
closeFd fd
|
closeFd fd
|
||||||
|
#endif
|
||||||
retry oldinfo metervar run = do
|
retry oldinfo metervar run = do
|
||||||
v <- tryAnnex run
|
v <- tryAnnex run
|
||||||
case v of
|
case v of
|
||||||
|
@ -195,8 +206,9 @@ startTransferInfo file = TransferInfo
|
||||||
{- If a transfer is still running, returns its TransferInfo. -}
|
{- If a transfer is still running, returns its TransferInfo. -}
|
||||||
checkTransfer :: Transfer -> Annex (Maybe TransferInfo)
|
checkTransfer :: Transfer -> Annex (Maybe TransferInfo)
|
||||||
checkTransfer t = do
|
checkTransfer t = do
|
||||||
mode <- annexFileMode
|
|
||||||
tfile <- fromRepo $ transferFile t
|
tfile <- fromRepo $ transferFile t
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
mode <- annexFileMode
|
||||||
mfd <- liftIO $ catchMaybeIO $
|
mfd <- liftIO $ catchMaybeIO $
|
||||||
openFd (transferLockFile tfile) ReadOnly (Just mode) defaultFileFlags
|
openFd (transferLockFile tfile) ReadOnly (Just mode) defaultFileFlags
|
||||||
case mfd of
|
case mfd of
|
||||||
|
@ -209,6 +221,13 @@ checkTransfer t = do
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just (pid, _) -> liftIO $ catchDefaultIO Nothing $
|
Just (pid, _) -> liftIO $ catchDefaultIO Nothing $
|
||||||
readTransferInfoFile (Just pid) tfile
|
readTransferInfoFile (Just pid) tfile
|
||||||
|
#else
|
||||||
|
ifM (liftIO $ doesFileExist $ transferLockFile tfile)
|
||||||
|
( liftIO $ catchDefaultIO Nothing $
|
||||||
|
readTransferInfoFile Nothing tfile
|
||||||
|
, return Nothing
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Gets all currently running transfers. -}
|
{- Gets all currently running transfers. -}
|
||||||
getTransfers :: Annex [(Transfer, TransferInfo)]
|
getTransfers :: Annex [(Transfer, TransferInfo)]
|
||||||
|
|
6
Remote/Directory.hs
Normal file → Executable file
6
Remote/Directory.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Remote.Directory (remote) where
|
module Remote.Directory (remote) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
|
@ -217,10 +219,14 @@ retrieveEncrypted d chunksize (cipher, enck) k f p = metered (Just p) k $ \meter
|
||||||
|
|
||||||
retrieveCheap :: FilePath -> ChunkSize -> Key -> FilePath -> Annex Bool
|
retrieveCheap :: FilePath -> ChunkSize -> Key -> FilePath -> Annex Bool
|
||||||
retrieveCheap _ (Just _) _ _ = return False -- no cheap retrieval for chunks
|
retrieveCheap _ (Just _) _ _ = return False -- no cheap retrieval for chunks
|
||||||
|
#ifndef __WINDOWS__
|
||||||
retrieveCheap d _ k f = liftIO $ withStoredFiles Nothing d k go
|
retrieveCheap d _ k f = liftIO $ withStoredFiles Nothing d k go
|
||||||
where
|
where
|
||||||
go [file] = catchBoolIO $ createSymbolicLink file f >> return True
|
go [file] = catchBoolIO $ createSymbolicLink file f >> return True
|
||||||
go _files = return False
|
go _files = return False
|
||||||
|
#else
|
||||||
|
retrieveCheap _ _ _ _ = return False
|
||||||
|
#endif
|
||||||
|
|
||||||
remove :: FilePath -> Key -> Annex Bool
|
remove :: FilePath -> Key -> Annex Bool
|
||||||
remove d k = liftIO $ do
|
remove d k = liftIO $ do
|
||||||
|
|
13
Remote/Git.hs
Normal file → Executable file
13
Remote/Git.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Remote.Git (
|
module Remote.Git (
|
||||||
remote,
|
remote,
|
||||||
configRead,
|
configRead,
|
||||||
|
@ -341,6 +343,7 @@ copyFromRemote' r key file dest
|
||||||
|
|
||||||
copyFromRemoteCheap :: Remote -> Key -> FilePath -> Annex Bool
|
copyFromRemoteCheap :: Remote -> Key -> FilePath -> Annex Bool
|
||||||
copyFromRemoteCheap r key file
|
copyFromRemoteCheap r key file
|
||||||
|
#ifndef __WINDOWS__
|
||||||
| not $ Git.repoIsUrl (repo r) = guardUsable (repo r) False $ do
|
| not $ Git.repoIsUrl (repo r) = guardUsable (repo r) False $ do
|
||||||
loc <- liftIO $ gitAnnexLocation key (repo r) $
|
loc <- liftIO $ gitAnnexLocation key (repo r) $
|
||||||
fromJust $ remoteGitConfig $ gitconfig r
|
fromJust $ remoteGitConfig $ gitconfig r
|
||||||
|
@ -350,6 +353,7 @@ copyFromRemoteCheap r key file
|
||||||
( copyFromRemote' r key Nothing file
|
( copyFromRemote' r key Nothing file
|
||||||
, return False
|
, return False
|
||||||
)
|
)
|
||||||
|
#endif
|
||||||
| otherwise = return False
|
| otherwise = return False
|
||||||
|
|
||||||
{- Tries to copy a key's content to a remote's annex. -}
|
{- Tries to copy a key's content to a remote's annex. -}
|
||||||
|
@ -396,12 +400,14 @@ rsyncHelper callback params = do
|
||||||
- filesystem. Then cp could be faster. -}
|
- filesystem. Then cp could be faster. -}
|
||||||
rsyncOrCopyFile :: [CommandParam] -> FilePath -> FilePath -> MeterUpdate -> Annex Bool
|
rsyncOrCopyFile :: [CommandParam] -> FilePath -> FilePath -> MeterUpdate -> Annex Bool
|
||||||
rsyncOrCopyFile rsyncparams src dest p =
|
rsyncOrCopyFile rsyncparams src dest p =
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
dorsync
|
||||||
|
where
|
||||||
|
#else
|
||||||
ifM (sameDeviceIds src dest) (docopy, dorsync)
|
ifM (sameDeviceIds src dest) (docopy, dorsync)
|
||||||
where
|
where
|
||||||
sameDeviceIds a b = (==) <$> (getDeviceId a) <*> (getDeviceId b)
|
sameDeviceIds a b = (==) <$> (getDeviceId a) <*> (getDeviceId b)
|
||||||
getDeviceId f = deviceID <$> liftIO (getFileStatus $ parentDir f)
|
getDeviceId f = deviceID <$> liftIO (getFileStatus $ parentDir f)
|
||||||
dorsync = rsyncHelper (Just p) $
|
|
||||||
rsyncparams ++ [Param src, Param dest]
|
|
||||||
docopy = liftIO $ bracket
|
docopy = liftIO $ bracket
|
||||||
(forkIO $ watchfilesize zeroBytesProcessed)
|
(forkIO $ watchfilesize zeroBytesProcessed)
|
||||||
(void . tryIO . killThread)
|
(void . tryIO . killThread)
|
||||||
|
@ -417,6 +423,9 @@ rsyncOrCopyFile rsyncparams src dest p =
|
||||||
p sz
|
p sz
|
||||||
watchfilesize sz
|
watchfilesize sz
|
||||||
_ -> watchfilesize oldsz
|
_ -> watchfilesize oldsz
|
||||||
|
#endif
|
||||||
|
dorsync = rsyncHelper (Just p) $
|
||||||
|
rsyncparams ++ [Param src, Param dest]
|
||||||
|
|
||||||
{- Generates rsync parameters that ssh to the remote and asks it
|
{- Generates rsync parameters that ssh to the remote and asks it
|
||||||
- to either receive or send the key's content. -}
|
- to either receive or send the key's content. -}
|
||||||
|
|
6
Remote/Helper/Hooks.hs
Normal file → Executable file
6
Remote/Helper/Hooks.hs
Normal file → Executable file
|
@ -5,6 +5,8 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Remote.Helper.Hooks (addHooks) where
|
module Remote.Helper.Hooks (addHooks) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
@ -70,6 +72,7 @@ runHooks r starthook stophook a = do
|
||||||
|
|
||||||
Annex.addCleanup (remoteid ++ "-stop-command") $ runstop lck
|
Annex.addCleanup (remoteid ++ "-stop-command") $ runstop lck
|
||||||
runstop lck = do
|
runstop lck = do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
-- Drop any shared lock we have, and take an
|
-- Drop any shared lock we have, and take an
|
||||||
-- exclusive lock, without blocking. If the lock
|
-- exclusive lock, without blocking. If the lock
|
||||||
-- succeeds, we're the only process using this remote,
|
-- succeeds, we're the only process using this remote,
|
||||||
|
@ -84,3 +87,6 @@ runHooks r starthook stophook a = do
|
||||||
Left _ -> noop
|
Left _ -> noop
|
||||||
Right _ -> run stophook
|
Right _ -> run stophook
|
||||||
liftIO $ closeFd fd
|
liftIO $ closeFd fd
|
||||||
|
#else
|
||||||
|
run stophook
|
||||||
|
#endif
|
||||||
|
|
|
@ -11,8 +11,10 @@ module Remote.Rsync (remote) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix.Process (getProcessID)
|
import System.Posix.Process (getProcessID)
|
||||||
|
#else
|
||||||
|
import System.Random (getStdRandom, random)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -219,10 +221,14 @@ sendParams = ifM crippledFileSystem
|
||||||
- up trees for rsync. -}
|
- up trees for rsync. -}
|
||||||
withRsyncScratchDir :: (FilePath -> Annex Bool) -> Annex Bool
|
withRsyncScratchDir :: (FilePath -> Annex Bool) -> Annex Bool
|
||||||
withRsyncScratchDir a = do
|
withRsyncScratchDir a = do
|
||||||
pid <- liftIO getProcessID
|
#ifndef __WINDOWS__
|
||||||
|
v <- liftIO getProcessID
|
||||||
|
#else
|
||||||
|
v <- liftIO (getStdRandom random :: IO Int)
|
||||||
|
#endif
|
||||||
t <- fromRepo gitAnnexTmpDir
|
t <- fromRepo gitAnnexTmpDir
|
||||||
createAnnexDirectory t
|
createAnnexDirectory t
|
||||||
let tmp = t </> "rsynctmp" </> show pid
|
let tmp = t </> "rsynctmp" </> show v
|
||||||
nuke tmp
|
nuke tmp
|
||||||
liftIO $ createDirectoryIfMissing True tmp
|
liftIO $ createDirectoryIfMissing True tmp
|
||||||
nuke tmp `after` a tmp
|
nuke tmp `after` a tmp
|
||||||
|
@ -273,8 +279,12 @@ rsyncSend o callback k canrename src = withRsyncScratchDir $ \tmp -> do
|
||||||
else ifM crippledFileSystem
|
else ifM crippledFileSystem
|
||||||
( liftIO $ copyFileExternal src dest
|
( liftIO $ copyFileExternal src dest
|
||||||
, do
|
, do
|
||||||
|
#ifndef __WINDOWS__
|
||||||
liftIO $ createLink src dest
|
liftIO $ createLink src dest
|
||||||
return True
|
return True
|
||||||
|
#else
|
||||||
|
liftIO $ copyFileExternal src dest
|
||||||
|
#endif
|
||||||
)
|
)
|
||||||
ps <- sendParams
|
ps <- sendParams
|
||||||
if ok
|
if ok
|
||||||
|
|
2
Seek.hs
Normal file → Executable file
2
Seek.hs
Normal file → Executable file
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
module Seek where
|
module Seek where
|
||||||
|
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Types.Command
|
import Types.Command
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
|
4
Test.hs
4
Test.hs
|
@ -5,19 +5,15 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
|
|
||||||
module Test where
|
module Test where
|
||||||
|
|
||||||
import Test.HUnit
|
import Test.HUnit
|
||||||
import Test.QuickCheck
|
import Test.QuickCheck
|
||||||
import Test.QuickCheck.Test
|
import Test.QuickCheck.Test
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
import System.Posix.Directory (changeWorkingDirectory)
|
import System.Posix.Directory (changeWorkingDirectory)
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
import System.Posix.Env
|
import System.Posix.Env
|
||||||
#endif
|
|
||||||
import Control.Exception.Extensible
|
import Control.Exception.Extensible
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import System.IO.HVFS (SystemFS(..))
|
import System.IO.HVFS (SystemFS(..))
|
||||||
|
|
9
Upgrade.hs
Normal file → Executable file
9
Upgrade.hs
Normal file → Executable file
|
@ -5,18 +5,27 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Upgrade where
|
module Upgrade where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Annex.Version
|
import Annex.Version
|
||||||
|
#ifndef __WINDOWS__
|
||||||
import qualified Upgrade.V0
|
import qualified Upgrade.V0
|
||||||
import qualified Upgrade.V1
|
import qualified Upgrade.V1
|
||||||
|
#endif
|
||||||
import qualified Upgrade.V2
|
import qualified Upgrade.V2
|
||||||
|
|
||||||
upgrade :: Annex Bool
|
upgrade :: Annex Bool
|
||||||
upgrade = go =<< getVersion
|
upgrade = go =<< getVersion
|
||||||
where
|
where
|
||||||
|
#ifndef __WINDOWS__
|
||||||
go (Just "0") = Upgrade.V0.upgrade
|
go (Just "0") = Upgrade.V0.upgrade
|
||||||
go (Just "1") = Upgrade.V1.upgrade
|
go (Just "1") = Upgrade.V1.upgrade
|
||||||
|
#else
|
||||||
|
go (Just "0") = error "upgrade from v0 on Windows not supported"
|
||||||
|
go (Just "1") = error "upgrade from v1 on Windows not supported"
|
||||||
|
#endif
|
||||||
go (Just "2") = Upgrade.V2.upgrade
|
go (Just "2") = Upgrade.V2.upgrade
|
||||||
go _ = return True
|
go _ = return True
|
||||||
|
|
0
Upgrade/V1.hs
Normal file → Executable file
0
Upgrade/V1.hs
Normal file → Executable file
|
@ -12,9 +12,10 @@ module Utility.Daemon where
|
||||||
import Common
|
import Common
|
||||||
import Utility.LogFile
|
import Utility.LogFile
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef __WINDOWS__
|
||||||
import System.Posix
|
import System.Posix
|
||||||
#endif
|
#endif
|
||||||
|
import System.Posix.Types
|
||||||
|
|
||||||
{- Run an action as a daemon, with all output sent to a file descriptor.
|
{- Run an action as a daemon, with all output sent to a file descriptor.
|
||||||
-
|
-
|
||||||
|
@ -23,6 +24,7 @@ import System.Posix
|
||||||
-
|
-
|
||||||
- When successful, does not return. -}
|
- When successful, does not return. -}
|
||||||
daemonize :: Fd -> Maybe FilePath -> Bool -> IO () -> IO ()
|
daemonize :: Fd -> Maybe FilePath -> Bool -> IO () -> IO ()
|
||||||
|
#ifndef __WINDOWS__
|
||||||
daemonize logfd pidfile changedirectory a = do
|
daemonize logfd pidfile changedirectory a = do
|
||||||
maybe noop checkalreadyrunning pidfile
|
maybe noop checkalreadyrunning pidfile
|
||||||
_ <- forkProcess child1
|
_ <- forkProcess child1
|
||||||
|
@ -44,11 +46,15 @@ daemonize logfd pidfile changedirectory a = do
|
||||||
a
|
a
|
||||||
out
|
out
|
||||||
out = exitImmediately ExitSuccess
|
out = exitImmediately ExitSuccess
|
||||||
|
#else
|
||||||
|
daemonize = error "daemonize TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Locks the pid file, with an exclusive, non-blocking lock.
|
{- Locks the pid file, with an exclusive, non-blocking lock.
|
||||||
- Writes the pid to the file, fully atomically.
|
- Writes the pid to the file, fully atomically.
|
||||||
- Fails if the pid file is already locked by another process. -}
|
- Fails if the pid file is already locked by another process. -}
|
||||||
lockPidFile :: FilePath -> IO ()
|
lockPidFile :: FilePath -> IO ()
|
||||||
|
#ifndef __WINDOWS__
|
||||||
lockPidFile file = do
|
lockPidFile file = do
|
||||||
createDirectoryIfMissing True (parentDir file)
|
createDirectoryIfMissing True (parentDir file)
|
||||||
fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags
|
fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags
|
||||||
|
@ -65,6 +71,9 @@ lockPidFile file = do
|
||||||
closeFd fd
|
closeFd fd
|
||||||
where
|
where
|
||||||
newfile = file ++ ".new"
|
newfile = file ++ ".new"
|
||||||
|
#else
|
||||||
|
lockPidFile = error "lockPidFile TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
alreadyRunning :: IO ()
|
alreadyRunning :: IO ()
|
||||||
alreadyRunning = error "Daemon is already running."
|
alreadyRunning = error "Daemon is already running."
|
||||||
|
@ -74,6 +83,7 @@ alreadyRunning = error "Daemon is already running."
|
||||||
-
|
-
|
||||||
- If it's running, returns its pid. -}
|
- If it's running, returns its pid. -}
|
||||||
checkDaemon :: FilePath -> IO (Maybe ProcessID)
|
checkDaemon :: FilePath -> IO (Maybe ProcessID)
|
||||||
|
#ifndef __WINDOWS__
|
||||||
checkDaemon pidfile = do
|
checkDaemon pidfile = do
|
||||||
v <- catchMaybeIO $
|
v <- catchMaybeIO $
|
||||||
openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags
|
openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags
|
||||||
|
@ -92,10 +102,17 @@ checkDaemon pidfile = do
|
||||||
"stale pid in " ++ pidfile ++
|
"stale pid in " ++ pidfile ++
|
||||||
" (got " ++ show pid' ++
|
" (got " ++ show pid' ++
|
||||||
"; expected " ++ show pid ++ " )"
|
"; expected " ++ show pid ++ " )"
|
||||||
|
#else
|
||||||
|
checkDaemon = error "checkDaemon TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Stops the daemon, safely. -}
|
{- Stops the daemon, safely. -}
|
||||||
stopDaemon :: FilePath -> IO ()
|
stopDaemon :: FilePath -> IO ()
|
||||||
|
#ifndef __WINDOWS__
|
||||||
stopDaemon pidfile = go =<< checkDaemon pidfile
|
stopDaemon pidfile = go =<< checkDaemon pidfile
|
||||||
where
|
where
|
||||||
go Nothing = noop
|
go Nothing = noop
|
||||||
go (Just pid) = signalProcess sigTERM pid
|
go (Just pid) = signalProcess sigTERM pid
|
||||||
|
#else
|
||||||
|
stopDaemon = error "stopDaemon TODO"
|
||||||
|
#endif
|
||||||
|
|
39
Utility/Env.hs
Executable file
39
Utility/Env.hs
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
{- portable environment variables
|
||||||
|
-
|
||||||
|
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
|
module Utility.Env where
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
import qualified System.Environment as E
|
||||||
|
import Utility.Exception
|
||||||
|
#else
|
||||||
|
import qualified System.Posix.Environment as E
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{- Posix getEnv is faster than the one in System.Environment,
|
||||||
|
- so use when available. -}
|
||||||
|
getEnv :: String -> IO (Maybe String)
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
getEnv = E.getEnv
|
||||||
|
#else
|
||||||
|
getEnv = catchMaybeIO . E.getEnv
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{- Returns True if it could successfully set the environment variable.
|
||||||
|
-
|
||||||
|
- There is, apparently, no way to do this in Windows. Instead,
|
||||||
|
- environment varuables must be provided when running a new process. -}
|
||||||
|
setEnv :: String -> String -> IO Bool
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
setEnv var val = do
|
||||||
|
E.setEnv var val
|
||||||
|
return True
|
||||||
|
#else
|
||||||
|
setEnv _ _ = return False
|
||||||
|
#endif
|
|
@ -113,10 +113,10 @@ isSticky = checkMode stickyMode
|
||||||
|
|
||||||
stickyMode :: FileMode
|
stickyMode :: FileMode
|
||||||
stickyMode = 512
|
stickyMode = 512
|
||||||
#endif
|
|
||||||
|
|
||||||
setSticky :: FilePath -> IO ()
|
setSticky :: FilePath -> IO ()
|
||||||
setSticky f = modifyFileMode f $ addModes [stickyMode]
|
setSticky f = modifyFileMode f $ addModes [stickyMode]
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Writes a file, ensuring that its modes do not allow it to be read
|
{- Writes a file, ensuring that its modes do not allow it to be read
|
||||||
- by anyone other than the current user, before any content is written.
|
- by anyone other than the current user, before any content is written.
|
||||||
|
|
3
Utility/InodeCache.hs
Normal file → Executable file
3
Utility/InodeCache.hs
Normal file → Executable file
|
@ -8,7 +8,8 @@
|
||||||
module Utility.InodeCache where
|
module Utility.InodeCache where
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
import System.Posix.Types
|
import System.PosixCompat.Types
|
||||||
|
import System.PosixCompat.Files
|
||||||
import Utility.QuickCheck
|
import Utility.QuickCheck
|
||||||
|
|
||||||
data InodeCachePrim = InodeCachePrim FileID FileOffset EpochTime
|
data InodeCachePrim = InodeCachePrim FileID FileOffset EpochTime
|
||||||
|
|
|
@ -11,15 +11,18 @@ module Utility.LogFile where
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
import System.Posix.Types
|
||||||
import System.Posix
|
import System.PosixCompat.Files
|
||||||
#endif
|
|
||||||
|
|
||||||
openLog :: FilePath -> IO Fd
|
openLog :: FilePath -> IO Fd
|
||||||
|
#ifndef __WINDOWS__
|
||||||
openLog logfile = do
|
openLog logfile = do
|
||||||
rotateLog logfile
|
rotateLog logfile
|
||||||
openFd logfile WriteOnly (Just stdFileMode)
|
openFd logfile WriteOnly (Just stdFileMode)
|
||||||
defaultFileFlags { append = True }
|
defaultFileFlags { append = True }
|
||||||
|
#else
|
||||||
|
openLog = error "openLog TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
rotateLog :: FilePath -> IO ()
|
rotateLog :: FilePath -> IO ()
|
||||||
rotateLog logfile = go 0
|
rotateLog logfile = go 0
|
||||||
|
@ -48,11 +51,19 @@ maxLogs :: Int
|
||||||
maxLogs = 9
|
maxLogs = 9
|
||||||
|
|
||||||
redirLog :: Fd -> IO ()
|
redirLog :: Fd -> IO ()
|
||||||
|
#ifndef __WINDOWS__
|
||||||
redirLog logfd = do
|
redirLog logfd = do
|
||||||
mapM_ (redir logfd) [stdOutput, stdError]
|
mapM_ (redir logfd) [stdOutput, stdError]
|
||||||
closeFd logfd
|
closeFd logfd
|
||||||
|
#else
|
||||||
|
redirLog _ = error "redirLog TODO"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __WINDOWS__
|
||||||
redir :: Fd -> Fd -> IO ()
|
redir :: Fd -> Fd -> IO ()
|
||||||
redir newh h = do
|
redir newh h = do
|
||||||
closeFd h
|
closeFd h
|
||||||
void $ dupTo newh h
|
void $ dupTo newh h
|
||||||
|
#else
|
||||||
|
redir _ _ = error "redir TODO"
|
||||||
|
#endif
|
||||||
|
|
|
@ -122,16 +122,18 @@ hGetSomeString h sz = do
|
||||||
peekbytes :: Int -> Ptr Word8 -> IO [Word8]
|
peekbytes :: Int -> Ptr Word8 -> IO [Word8]
|
||||||
peekbytes len buf = mapM (peekElemOff buf) [0..pred len]
|
peekbytes len buf = mapM (peekElemOff buf) [0..pred len]
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
{- Reaps any zombie git processes.
|
{- Reaps any zombie git processes.
|
||||||
-
|
-
|
||||||
- Warning: Not thread safe. Anything that was expecting to wait
|
- Warning: Not thread safe. Anything that was expecting to wait
|
||||||
- on a process and get back an exit status is going to be confused
|
- on a process and get back an exit status is going to be confused
|
||||||
- if this reap gets there first. -}
|
- if this reap gets there first. -}
|
||||||
reapZombies :: IO ()
|
reapZombies :: IO ()
|
||||||
|
#ifndef mingw32_HOST_OS
|
||||||
reapZombies = do
|
reapZombies = do
|
||||||
-- throws an exception when there are no child processes
|
-- throws an exception when there are no child processes
|
||||||
catchDefaultIO Nothing (getAnyProcessStatus False True)
|
catchDefaultIO Nothing (getAnyProcessStatus False True)
|
||||||
>>= maybe (return ()) (const reapZombies)
|
>>= maybe (return ()) (const reapZombies)
|
||||||
|
|
||||||
|
#else
|
||||||
|
reapZombies = return ()
|
||||||
#endif
|
#endif
|
||||||
|
|
1
Utility/Url.hs
Normal file → Executable file
1
Utility/Url.hs
Normal file → Executable file
|
@ -20,6 +20,7 @@ import Network.URI
|
||||||
import qualified Network.Browser as Browser
|
import qualified Network.Browser as Browser
|
||||||
import Network.HTTP
|
import Network.HTTP
|
||||||
import Data.Either
|
import Data.Either
|
||||||
|
import System.PosixCompat.Files
|
||||||
|
|
||||||
import qualified Build.SysConfig
|
import qualified Build.SysConfig
|
||||||
|
|
||||||
|
|
|
@ -14,45 +14,31 @@ module Utility.UserInfo (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
#ifndef mingw32_HOST_OS
|
import System.Posix.Types
|
||||||
import System.Posix.User
|
import System.PosixCompat
|
||||||
import System.Posix.Env
|
|
||||||
#endif
|
import Utility.Env
|
||||||
|
|
||||||
{- Current user's home directory.
|
{- Current user's home directory.
|
||||||
-
|
-
|
||||||
- getpwent will fail on LDAP or NIS, so use HOME if set. -}
|
- getpwent will fail on LDAP or NIS, so use HOME if set. -}
|
||||||
myHomeDir :: IO FilePath
|
myHomeDir :: IO FilePath
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
myHomeDir = myVal ["HOME"] homeDirectory
|
myHomeDir = myVal ["HOME"] homeDirectory
|
||||||
#else
|
|
||||||
myHomeDir = error "myHomeDir TODO"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{- Current user's user name. -}
|
{- Current user's user name. -}
|
||||||
myUserName :: IO String
|
myUserName :: IO String
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
myUserName = myVal ["USER", "LOGNAME"] userName
|
myUserName = myVal ["USER", "LOGNAME"] userName
|
||||||
#else
|
|
||||||
myUserName = error "myUserName TODO"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
myUserGecos :: IO String
|
myUserGecos :: IO String
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
myUserGecos = return "" -- userGecos crashes on Android
|
myUserGecos = return "" -- userGecos crashes on Android
|
||||||
#else
|
#else
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
myUserGecos = myVal [] userGecos
|
myUserGecos = myVal [] userGecos
|
||||||
#else
|
|
||||||
myUserGecos = error "myUserGecos TODO"
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
|
||||||
myVal :: [String] -> (UserEntry -> String) -> IO String
|
myVal :: [String] -> (UserEntry -> String) -> IO String
|
||||||
myVal envvars extract = maybe (extract <$> getpwent) return =<< check envvars
|
myVal envvars extract = maybe (extract <$> getpwent) return =<< check envvars
|
||||||
where
|
where
|
||||||
check [] = return Nothing
|
check [] = return Nothing
|
||||||
check (v:vs) = maybe (check vs) (return . Just) =<< getEnv v
|
check (v:vs) = maybe (check vs) (return . Just) =<< getEnv v
|
||||||
getpwent = getUserEntryForID =<< getEffectiveUserID
|
getpwent = getUserEntryForID =<< getEffectiveUserID
|
||||||
#endif
|
|
||||||
|
|
5
git-annex.hs
Normal file → Executable file
5
git-annex.hs
Normal file → Executable file
|
@ -13,7 +13,10 @@ import System.FilePath
|
||||||
import qualified GitAnnex
|
import qualified GitAnnex
|
||||||
import qualified GitAnnexShell
|
import qualified GitAnnexShell
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef WITH_TESTSUITE
|
||||||
|
#ifndef __WINDOWS__
|
||||||
import qualified Test
|
import qualified Test
|
||||||
|
#define CHECK_TEST
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
@ -25,7 +28,7 @@ main = run =<< getProgName
|
||||||
isshell n = takeFileName n == "git-annex-shell"
|
isshell n = takeFileName n == "git-annex-shell"
|
||||||
go a = do
|
go a = do
|
||||||
ps <- getArgs
|
ps <- getArgs
|
||||||
#ifdef WITH_TESTSUITE
|
#ifdef CHECK_TEST
|
||||||
if ps == ["test"]
|
if ps == ["test"]
|
||||||
then Test.main
|
then Test.main
|
||||||
else a ps
|
else a ps
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue