cleanup thanks to Utility.PID

This commit is contained in:
Joey Hess 2014-02-11 15:29:56 -04:00
parent c390e896d1
commit 7b19c7d25b
5 changed files with 18 additions and 34 deletions

View file

@ -16,6 +16,7 @@ import Assistant.NamedThread
import Utility.ThreadScheduler import Utility.ThreadScheduler
import Utility.NotificationBroadcaster import Utility.NotificationBroadcaster
import Utility.Url import Utility.Url
import Utility.PID
import qualified Git.Construct import qualified Git.Construct
import qualified Git.Config import qualified Git.Config
import Config.Files import Config.Files
@ -25,9 +26,8 @@ import qualified Git
import Control.Concurrent import Control.Concurrent
import System.Process (cwd) import System.Process (cwd)
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
import System.Posix (getProcessID, signalProcess, sigTERM) import System.Posix (signalProcess, sigTERM)
#else #else
import System.Win32.Process.Current (getCurrentProcessId)
import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT) import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT)
#endif #endif
@ -53,9 +53,9 @@ postRestart url = do
void $ liftIO $ forkIO $ do void $ liftIO $ forkIO $ do
threadDelaySeconds (Seconds 120) threadDelaySeconds (Seconds 120)
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
signalProcess sigTERM =<< getProcessID signalProcess sigTERM =<< getPID
#else #else
generateConsoleCtrlEvent cTRL_C_EVENT =<< getCurrentProcessId generateConsoleCtrlEvent cTRL_C_EVENT =<< getPID
#endif #endif
runRestart :: Assistant URLString runRestart :: Assistant URLString

View file

@ -16,14 +16,14 @@ import Assistant.TransferSlots
import Assistant.Restart import Assistant.Restart
import Utility.LogFile import Utility.LogFile
import Utility.NotificationBroadcaster import Utility.NotificationBroadcaster
import Utility.PID
import Control.Concurrent import Control.Concurrent
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.Text as T import qualified Data.Text as T
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
import System.Posix (getProcessID, signalProcess, sigTERM) import System.Posix (signalProcess, sigTERM)
#else #else
import System.Win32.Process.Current (getCurrentProcessId)
import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT) import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT)
#endif #endif
@ -54,9 +54,9 @@ getShutdownConfirmedR = do
void $ liftIO $ forkIO $ do void $ liftIO $ forkIO $ do
threadDelay 2000000 threadDelay 2000000
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
signalProcess sigTERM =<< getProcessID signalProcess sigTERM =<< getPID
#else #else
generateConsoleCtrlEvent cTRL_C_EVENT =<< getCurrentProcessId generateConsoleCtrlEvent cTRL_C_EVENT =<< getPID
#endif #endif
redirect NotRunningR redirect NotRunningR

View file

@ -31,12 +31,8 @@ import Config
import Types.Key import Types.Key
import Utility.HumanTime import Utility.HumanTime
import Git.FilePath import Git.FilePath
import Utility.PID
#ifndef mingw32_HOST_OS
import System.Posix.Process (getProcessID)
#else
import System.Win32.Process.Current (getCurrentProcessId)
#endif
import Data.Time.Clock.POSIX import Data.Time.Clock.POSIX
import Data.Time import Data.Time
import System.Posix.Types (EpochTime) import System.Posix.Types (EpochTime)
@ -149,14 +145,10 @@ performRemote key file backend numcopies remote =
, checkKeyNumCopies key file numcopies , checkKeyNumCopies key file numcopies
] ]
withtmp a = do withtmp a = do
#ifndef mingw32_HOST_OS pid <- liftIO getPID
v <- liftIO getProcessID
#else
v <- liftIO getCurrentProcessId
#endif
t <- fromRepo gitAnnexTmpDir t <- fromRepo gitAnnexTmpDir
createAnnexDirectory t createAnnexDirectory t
let tmp = t </> "fsck" ++ show v ++ "." ++ keyFile key let tmp = t </> "fsck" ++ show pid ++ "." ++ 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

View file

@ -18,14 +18,6 @@ module Remote.Rsync (
RsyncOpts RsyncOpts
) where ) where
import qualified Data.ByteString.Lazy as L
import qualified Data.Map as M
#ifndef mingw32_HOST_OS
import System.Posix.Process (getProcessID)
#else
import System.Win32.Process.Current (getCurrentProcessId)
#endif
import Common.Annex import Common.Annex
import Types.Remote import Types.Remote
import qualified Git import qualified Git
@ -40,10 +32,14 @@ import Crypto
import Utility.Rsync import Utility.Rsync
import Utility.CopyFile import Utility.CopyFile
import Utility.Metered import Utility.Metered
import Utility.PID
import Annex.Perms import Annex.Perms
import Logs.Transfer import Logs.Transfer
import Types.Creds import Types.Creds
import qualified Data.ByteString.Lazy as L
import qualified Data.Map as M
type RsyncUrl = String type RsyncUrl = String
data RsyncOpts = RsyncOpts data RsyncOpts = RsyncOpts
@ -250,14 +246,10 @@ sendParams = ifM crippledFileSystem
- up trees for rsync. -} - up trees for rsync. -}
withRsyncScratchDir :: (FilePath -> Annex a) -> Annex a withRsyncScratchDir :: (FilePath -> Annex a) -> Annex a
withRsyncScratchDir a = do withRsyncScratchDir a = do
#ifndef mingw32_HOST_OS p <- liftIO getPID
v <- liftIO getProcessID
#else
v <- liftIO getCurrentProcessId
#endif
t <- fromRepo gitAnnexTmpDir t <- fromRepo gitAnnexTmpDir
createAnnexDirectory t createAnnexDirectory t
let tmp = t </> "rsynctmp" </> show v let tmp = t </> "rsynctmp" </> show p
nuke tmp nuke tmp
liftIO $ createDirectoryIfMissing True tmp liftIO $ createDirectoryIfMissing True tmp
nuke tmp `after` a tmp nuke tmp `after` a tmp

View file

@ -20,7 +20,7 @@ import System.Posix
import Control.Concurrent.Async import Control.Concurrent.Async
#else #else
import System.PosixCompat.Types import System.PosixCompat.Types
import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT)
#endif #endif
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS