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 Trust
|
||||||
import Utility.DataUnits
|
import Utility.DataUnits
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
|
import Utility.FileMode
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
|
|
|
@ -18,6 +18,7 @@ import qualified Annex
|
||||||
import qualified AnnexQueue
|
import qualified AnnexQueue
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
|
import Utility.FileMode
|
||||||
import LocationLog
|
import LocationLog
|
||||||
import Types
|
import Types
|
||||||
import Content
|
import Content
|
||||||
|
|
|
@ -19,6 +19,7 @@ import Content
|
||||||
import Utility.Conditional
|
import Utility.Conditional
|
||||||
import Utility.CopyFile
|
import Utility.CopyFile
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
|
import Utility.FileMode
|
||||||
|
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
command =
|
command =
|
||||||
|
|
|
@ -184,7 +184,7 @@ getKeysReferenced = do
|
||||||
staleKeysPrune :: (Git.Repo -> FilePath) -> [Key] -> Annex [Key]
|
staleKeysPrune :: (Git.Repo -> FilePath) -> [Key] -> Annex [Key]
|
||||||
staleKeysPrune dirspec present = do
|
staleKeysPrune dirspec present = do
|
||||||
contents <- staleKeys dirspec
|
contents <- staleKeys dirspec
|
||||||
|
|
||||||
let stale = contents `exclude` present
|
let stale = contents `exclude` present
|
||||||
let dup = contents `exclude` stale
|
let dup = contents `exclude` stale
|
||||||
|
|
||||||
|
|
16
Content.hs
16
Content.hs
|
@ -13,8 +13,6 @@ module Content (
|
||||||
getViaTmpUnchecked,
|
getViaTmpUnchecked,
|
||||||
withTmp,
|
withTmp,
|
||||||
checkDiskSpace,
|
checkDiskSpace,
|
||||||
preventWrite,
|
|
||||||
allowWrite,
|
|
||||||
moveAnnex,
|
moveAnnex,
|
||||||
removeAnnex,
|
removeAnnex,
|
||||||
fromAnnex,
|
fromAnnex,
|
||||||
|
@ -43,6 +41,7 @@ import Utility
|
||||||
import Utility.Conditional
|
import Utility.Conditional
|
||||||
import Utility.StatFS
|
import Utility.StatFS
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
|
import Utility.FileMode
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Utility.DataUnits
|
import Utility.DataUnits
|
||||||
import Config
|
import Config
|
||||||
|
@ -152,19 +151,6 @@ checkDiskSpace' adjustment key = do
|
||||||
roughSize storageUnits True n ++
|
roughSize storageUnits True n ++
|
||||||
" more (use --force to override this check or adjust annex.diskreserve)"
|
" 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/
|
{- Moves a file into .git/annex/objects/
|
||||||
-
|
-
|
||||||
- What if the key there already has content? This could happen for
|
- What if the key there already has content? This could happen for
|
||||||
|
|
|
@ -25,10 +25,10 @@ import UUID
|
||||||
import Locations
|
import Locations
|
||||||
import Utility.CopyFile
|
import Utility.CopyFile
|
||||||
import Config
|
import Config
|
||||||
import Content
|
|
||||||
import Utility
|
import Utility
|
||||||
import Utility.Conditional
|
import Utility.Conditional
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
|
import Utility.FileMode
|
||||||
import Remote.Helper.Special
|
import Remote.Helper.Special
|
||||||
import Remote.Helper.Encryptable
|
import Remote.Helper.Encryptable
|
||||||
import Crypto
|
import Crypto
|
||||||
|
|
|
@ -32,6 +32,7 @@ import Backend
|
||||||
import Messages
|
import Messages
|
||||||
import Version
|
import Version
|
||||||
import Utility
|
import Utility
|
||||||
|
import Utility.FileMode
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
import qualified Upgrade.V2
|
import qualified Upgrade.V2
|
||||||
|
|
11
Utility.hs
11
Utility.hs
|
@ -8,7 +8,6 @@
|
||||||
module Utility (
|
module Utility (
|
||||||
hGetContentsStrict,
|
hGetContentsStrict,
|
||||||
readFileStrict,
|
readFileStrict,
|
||||||
unsetFileMode,
|
|
||||||
readMaybe,
|
readMaybe,
|
||||||
viaTmp,
|
viaTmp,
|
||||||
withTempFile,
|
withTempFile,
|
||||||
|
@ -24,12 +23,9 @@ module Utility (
|
||||||
import IO (bracket)
|
import IO (bracket)
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Posix.Process hiding (executeFile)
|
import System.Posix.Process hiding (executeFile)
|
||||||
import System.Posix.Files
|
|
||||||
import System.Posix.Types
|
|
||||||
import System.Posix.User
|
import System.Posix.User
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Foreign (complement)
|
|
||||||
import Utility.Path
|
import Utility.Path
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Monad (liftM)
|
import Control.Monad (liftM)
|
||||||
|
@ -43,13 +39,6 @@ hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
|
||||||
readFileStrict :: FilePath -> IO String
|
readFileStrict :: FilePath -> IO String
|
||||||
readFileStrict f = readFile f >>= \s -> length s `seq` return s
|
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. -}
|
{- Attempts to read a value from a String. -}
|
||||||
readMaybe :: (Read a) => String -> Maybe a
|
readMaybe :: (Read a) => String -> Maybe a
|
||||||
readMaybe s = case reads s of
|
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