support Android's crippled lsof
This commit is contained in:
parent
a7ef05a988
commit
5737c49804
3 changed files with 28 additions and 7 deletions
|
@ -281,7 +281,10 @@ safeToAdd delayadd pending inprocess = do
|
||||||
void $ liftIO $ tryIO $ removeFile $ contentLocation ks
|
void $ liftIO $ tryIO $ removeFile $ contentLocation ks
|
||||||
canceladd _ = noop
|
canceladd _ = noop
|
||||||
|
|
||||||
openwrite (_file, mode, _pid) =
|
openwrite (_file, mode, _pid)
|
||||||
mode == Lsof.OpenWriteOnly || mode == Lsof.OpenReadWrite
|
| mode == Lsof.OpenWriteOnly = True
|
||||||
|
| mode == Lsof.OpenReadWrite = True
|
||||||
|
| mode == Lsof.OpenUnknown = True
|
||||||
|
| otherwise = False
|
||||||
|
|
||||||
allRight = return . map Right
|
allRight = return . map Right
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE BangPatterns #-}
|
{-# LANGUAGE BangPatterns, CPP #-}
|
||||||
|
|
||||||
module Utility.Lsof where
|
module Utility.Lsof where
|
||||||
|
|
||||||
|
@ -52,6 +52,15 @@ query opts =
|
||||||
where
|
where
|
||||||
p = proc "lsof" ("-F0can" : opts)
|
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:
|
{- Parsing null-delimited output like:
|
||||||
-
|
-
|
||||||
- pPID\0cCMDLINE\0
|
- pPID\0cCMDLINE\0
|
||||||
|
@ -62,8 +71,8 @@ query opts =
|
||||||
- Where each new process block is started by a pid, and a process can
|
- Where each new process block is started by a pid, and a process can
|
||||||
- have multiple files open.
|
- have multiple files open.
|
||||||
-}
|
-}
|
||||||
parse :: String -> [(FilePath, LsofOpenMode, ProcessInfo)]
|
parseFormatted :: LsofParser
|
||||||
parse s = bundle $ go [] $ lines s
|
parseFormatted s = bundle $ go [] $ lines s
|
||||||
where
|
where
|
||||||
bundle = concatMap (\(fs, p) -> map (\(f, m) -> (f, m, p)) fs)
|
bundle = concatMap (\(fs, p) -> map (\(f, m) -> (f, m, p)) fs)
|
||||||
|
|
||||||
|
@ -97,3 +106,14 @@ parse s = bundle $ go [] $ lines s
|
||||||
splitnull = split "\0"
|
splitnull = split "\0"
|
||||||
|
|
||||||
parsefail = error $ "failed to parse lsof output: " ++ show s
|
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
|
||||||
|
|
|
@ -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
|
* 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.
|
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
|
### Android specific features
|
||||||
|
|
||||||
The app should be aware of power status, and avoid expensive background
|
The app should be aware of power status, and avoid expensive background
|
||||||
|
|
Loading…
Reference in a new issue