summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-11 17:24:12 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-11 17:33:45 -0400
commitfc1f365321bcb9ca4e737c3219393c390c2f85d7 (patch)
tree92379482d1cdb9dd581c4d4b987521e4ae43aa7e
parentc4e7c6af35c3abf66b4c0c68d4224ae010e1f2a8 (diff)
support Android's crippled lsof
-rw-r--r--Assistant/Threads/Committer.hs7
-rw-r--r--Utility/Lsof.hs26
-rw-r--r--doc/design/assistant/android.mdwn2
3 files changed, 28 insertions, 7 deletions
diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs
index d90b0e1cb..ce39735f9 100644
--- a/Assistant/Threads/Committer.hs
+++ b/Assistant/Threads/Committer.hs
@@ -281,7 +281,10 @@ safeToAdd delayadd pending inprocess = do
void $ liftIO $ tryIO $ removeFile $ contentLocation ks
canceladd _ = noop
- openwrite (_file, mode, _pid) =
- mode == Lsof.OpenWriteOnly || mode == Lsof.OpenReadWrite
+ openwrite (_file, mode, _pid)
+ | mode == Lsof.OpenWriteOnly = True
+ | mode == Lsof.OpenReadWrite = True
+ | mode == Lsof.OpenUnknown = True
+ | otherwise = False
allRight = return . map Right
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs
index 9a877a3c9..6e1d2f084 100644
--- a/Utility/Lsof.hs
+++ b/Utility/Lsof.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE BangPatterns, CPP #-}
module Utility.Lsof where
@@ -52,6 +52,15 @@ query opts =
where
p = proc "lsof" ("-F0can" : opts)
+type LsofParser = String -> [(FilePath, LsofOpenMode, ProcessInfo)]
+
+parse :: LsofParser
+#ifdef WITH_ANDROID
+parse = parseDefault
+#else
+parse = parseFormatted
+#endif
+
{- Parsing null-delimited output like:
-
- pPID\0cCMDLINE\0
@@ -62,8 +71,8 @@ query opts =
- Where each new process block is started by a pid, and a process can
- have multiple files open.
-}
-parse :: String -> [(FilePath, LsofOpenMode, ProcessInfo)]
-parse s = bundle $ go [] $ lines s
+parseFormatted :: LsofParser
+parseFormatted s = bundle $ go [] $ lines s
where
bundle = concatMap (\(fs, p) -> map (\(f, m) -> (f, m, p)) fs)
@@ -97,3 +106,14 @@ parse s = bundle $ go [] $ lines s
splitnull = split "\0"
parsefail = error $ "failed to parse lsof output: " ++ show s
+
+{- Parses lsof's default output format. -}
+parseDefault :: LsofParser
+parseDefault = catMaybes . map parse . drop 1 . lines
+ where
+ parse l = case words l of
+ (command : spid : _user : _fd : _type : _device : _size : _node : rest) ->
+ case readish spid of
+ Nothing -> Nothing
+ Just pid -> Just (unwords rest, OpenUnknown, ProcessInfo pid command)
+ _ -> Nothing
diff --git a/doc/design/assistant/android.mdwn b/doc/design/assistant/android.mdwn
index 3c6abfd13..170a45a0f 100644
--- a/doc/design/assistant/android.mdwn
+++ b/doc/design/assistant/android.mdwn
@@ -24,8 +24,6 @@ and also have to `cabal install` all necessary dependencies.
* git-annex sets `#!/bin/sh` in hook script, but that is not
a valid path on android, and the right path needs to be determined at runtime.
-* support Android lsof output in lsof parser, needed for watch mode
-
### Android specific features
The app should be aware of power status, and avoid expensive background