add
This commit is contained in:
parent
e64d1becf4
commit
d0e82d0b92
1 changed files with 29 additions and 0 deletions
29
Utility.hs
Normal file
29
Utility.hs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{- git-annex utility functions
|
||||||
|
-}
|
||||||
|
|
||||||
|
module Utility where
|
||||||
|
|
||||||
|
import System.IO
|
||||||
|
import System.Posix.IO
|
||||||
|
import Data.String.Utils
|
||||||
|
|
||||||
|
{- Let's just say that Haskell makes reading/writing a file with
|
||||||
|
- file locking excessively difficult. -}
|
||||||
|
openLocked file mode = do
|
||||||
|
handle <- openFile file mode
|
||||||
|
lockfd <- handleToFd handle -- closes handle
|
||||||
|
waitToSetLock lockfd (lockType mode, AbsoluteSeek, 0, 0)
|
||||||
|
handle' <- fdToHandle lockfd
|
||||||
|
return handle'
|
||||||
|
where
|
||||||
|
lockType ReadMode = ReadLock
|
||||||
|
lockType _ = WriteLock
|
||||||
|
|
||||||
|
{- Returns the parent directory of a path. Parent of / is "" -}
|
||||||
|
parentDir :: String -> String
|
||||||
|
parentDir dir =
|
||||||
|
if length dirs > 0
|
||||||
|
then "/" ++ (join "/" $ take ((length dirs) - 1) dirs)
|
||||||
|
else ""
|
||||||
|
where
|
||||||
|
dirs = filter (\x -> length x > 0) $ split "/" dir
|
Loading…
Add table
Add a link
Reference in a new issue