summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-23 18:13:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-23 18:13:24 -0400
commit4bf1a5ef59026a095abf751ea60b586c299aa0b9 (patch)
tree067cd0813f3f315475b3b958762ed569ae95e8de
parentd75da353b9905bb5757df08520e63607fbfd2073 (diff)
refactor
-rw-r--r--Command/Fsck.hs1
-rw-r--r--Command/Unannex.hs1
-rw-r--r--Command/Unlock.hs1
-rw-r--r--Command/Unused.hs2
-rw-r--r--Content.hs16
-rw-r--r--Remote/Directory.hs2
-rw-r--r--Upgrade/V1.hs1
-rw-r--r--Utility.hs11
-rw-r--r--Utility/FileMode.hs32
9 files changed, 39 insertions, 28 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 142f755a7..0c58add6a 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -26,6 +26,7 @@ import Locations
import Trust
import Utility.DataUnits
import Utility.Path
+import Utility.FileMode
import Config
command :: [Command]
diff --git a/Command/Unannex.hs b/Command/Unannex.hs
index 3dedd007e..4d4281eb0 100644
--- a/Command/Unannex.hs
+++ b/Command/Unannex.hs
@@ -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
diff --git a/Command/Unlock.hs b/Command/Unlock.hs
index 5817e8f22..44b92545c 100644
--- a/Command/Unlock.hs
+++ b/Command/Unlock.hs
@@ -19,6 +19,7 @@ import Content
import Utility.Conditional
import Utility.CopyFile
import Utility.Path
+import Utility.FileMode
command :: [Command]
command =
diff --git a/Command/Unused.hs b/Command/Unused.hs
index 803debef8..f62e68c30 100644
--- a/Command/Unused.hs
+++ b/Command/Unused.hs
@@ -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
diff --git a/Content.hs b/Content.hs
index e4bbee528..f963c48b4 100644
--- a/Content.hs
+++ b/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
diff --git a/Remote/Directory.hs b/Remote/Directory.hs
index b183042ef..18835c5de 100644
--- a/Remote/Directory.hs
+++ b/Remote/Directory.hs
@@ -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
diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs
index 78f7d3adb..329f90ed6 100644
--- a/Upgrade/V1.hs
+++ b/Upgrade/V1.hs
@@ -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
diff --git a/Utility.hs b/Utility.hs
index ce1736348..a3d461d28 100644
--- a/Utility.hs
+++ b/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
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs
new file mode 100644
index 000000000..f5b018c84
--- /dev/null
+++ b/Utility/FileMode.hs
@@ -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