refactor
This commit is contained in:
parent
d75da353b9
commit
4bf1a5ef59
9 changed files with 39 additions and 28 deletions
|
@ -26,6 +26,7 @@ import Locations
|
|||
import Trust
|
||||
import Utility.DataUnits
|
||||
import Utility.Path
|
||||
import Utility.FileMode
|
||||
import Config
|
||||
|
||||
command :: [Command]
|
||||
|
|
|
@ -18,6 +18,7 @@ import qualified Annex
|
|||
import qualified AnnexQueue
|
||||
import Utility.SafeCommand
|
||||
import Utility.Path
|
||||
import Utility.FileMode
|
||||
import LocationLog
|
||||
import Types
|
||||
import Content
|
||||
|
|
|
@ -19,6 +19,7 @@ import Content
|
|||
import Utility.Conditional
|
||||
import Utility.CopyFile
|
||||
import Utility.Path
|
||||
import Utility.FileMode
|
||||
|
||||
command :: [Command]
|
||||
command =
|
||||
|
|
|
@ -184,7 +184,7 @@ getKeysReferenced = do
|
|||
staleKeysPrune :: (Git.Repo -> FilePath) -> [Key] -> Annex [Key]
|
||||
staleKeysPrune dirspec present = do
|
||||
contents <- staleKeys dirspec
|
||||
|
||||
|
||||
let stale = contents `exclude` present
|
||||
let dup = contents `exclude` stale
|
||||
|
||||
|
|
16
Content.hs
16
Content.hs
|
@ -13,8 +13,6 @@ module Content (
|
|||
getViaTmpUnchecked,
|
||||
withTmp,
|
||||
checkDiskSpace,
|
||||
preventWrite,
|
||||
allowWrite,
|
||||
moveAnnex,
|
||||
removeAnnex,
|
||||
fromAnnex,
|
||||
|
@ -43,6 +41,7 @@ import Utility
|
|||
import Utility.Conditional
|
||||
import Utility.StatFS
|
||||
import Utility.Path
|
||||
import Utility.FileMode
|
||||
import Types.Key
|
||||
import Utility.DataUnits
|
||||
import Config
|
||||
|
@ -152,19 +151,6 @@ checkDiskSpace' adjustment key = do
|
|||
roughSize storageUnits True n ++
|
||||
" more (use --force to override this check or adjust annex.diskreserve)"
|
||||
|
||||
{- Removes the write bits from a file. -}
|
||||
preventWrite :: FilePath -> IO ()
|
||||
preventWrite f = unsetFileMode f writebits
|
||||
where
|
||||
writebits = foldl unionFileModes ownerWriteMode
|
||||
[groupWriteMode, otherWriteMode]
|
||||
|
||||
{- Turns a file's write bit back on. -}
|
||||
allowWrite :: FilePath -> IO ()
|
||||
allowWrite f = do
|
||||
s <- getFileStatus f
|
||||
setFileMode f $ fileMode s `unionFileModes` ownerWriteMode
|
||||
|
||||
{- Moves a file into .git/annex/objects/
|
||||
-
|
||||
- What if the key there already has content? This could happen for
|
||||
|
|
|
@ -25,10 +25,10 @@ import UUID
|
|||
import Locations
|
||||
import Utility.CopyFile
|
||||
import Config
|
||||
import Content
|
||||
import Utility
|
||||
import Utility.Conditional
|
||||
import Utility.Path
|
||||
import Utility.FileMode
|
||||
import Remote.Helper.Special
|
||||
import Remote.Helper.Encryptable
|
||||
import Crypto
|
||||
|
|
|
@ -32,6 +32,7 @@ import Backend
|
|||
import Messages
|
||||
import Version
|
||||
import Utility
|
||||
import Utility.FileMode
|
||||
import Utility.SafeCommand
|
||||
import Utility.Path
|
||||
import qualified Upgrade.V2
|
||||
|
|
11
Utility.hs
11
Utility.hs
|
@ -8,7 +8,6 @@
|
|||
module Utility (
|
||||
hGetContentsStrict,
|
||||
readFileStrict,
|
||||
unsetFileMode,
|
||||
readMaybe,
|
||||
viaTmp,
|
||||
withTempFile,
|
||||
|
@ -24,12 +23,9 @@ module Utility (
|
|||
import IO (bracket)
|
||||
import System.IO
|
||||
import System.Posix.Process hiding (executeFile)
|
||||
import System.Posix.Files
|
||||
import System.Posix.Types
|
||||
import System.Posix.User
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
import Foreign (complement)
|
||||
import Utility.Path
|
||||
import Data.Maybe
|
||||
import Control.Monad (liftM)
|
||||
|
@ -43,13 +39,6 @@ hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
|
|||
readFileStrict :: FilePath -> IO String
|
||||
readFileStrict f = readFile f >>= \s -> length s `seq` return s
|
||||
|
||||
{- Removes a FileMode from a file.
|
||||
- For example, call with otherWriteMode to chmod o-w -}
|
||||
unsetFileMode :: FilePath -> FileMode -> IO ()
|
||||
unsetFileMode f m = do
|
||||
s <- getFileStatus f
|
||||
setFileMode f $ fileMode s `intersectFileModes` complement m
|
||||
|
||||
{- Attempts to read a value from a String. -}
|
||||
readMaybe :: (Read a) => String -> Maybe a
|
||||
readMaybe s = case reads s of
|
||||
|
|
32
Utility/FileMode.hs
Normal file
32
Utility/FileMode.hs
Normal file
|
@ -0,0 +1,32 @@
|
|||
{- File mode utilities.
|
||||
-
|
||||
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Utility.FileMode where
|
||||
|
||||
import System.Posix.Files
|
||||
import System.Posix.Types
|
||||
import Foreign (complement)
|
||||
|
||||
{- Removes a FileMode from a file.
|
||||
- For example, call with otherWriteMode to chmod o-w -}
|
||||
unsetFileMode :: FilePath -> FileMode -> IO ()
|
||||
unsetFileMode f m = do
|
||||
s <- getFileStatus f
|
||||
setFileMode f $ fileMode s `intersectFileModes` complement m
|
||||
|
||||
{- Removes the write bits from a file. -}
|
||||
preventWrite :: FilePath -> IO ()
|
||||
preventWrite f = unsetFileMode f writebits
|
||||
where
|
||||
writebits = foldl unionFileModes ownerWriteMode
|
||||
[groupWriteMode, otherWriteMode]
|
||||
|
||||
{- Turns a file's write bit back on. -}
|
||||
allowWrite :: FilePath -> IO ()
|
||||
allowWrite f = do
|
||||
s <- getFileStatus f
|
||||
setFileMode f $ fileMode s `unionFileModes` ownerWriteMode
|
Loading…
Reference in a new issue