summaryrefslogtreecommitdiff
path: root/Utility/FileMode.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <id@joeyh.name>2013-05-10 16:29:59 -0500
committerGravatar Joey Hess <id@joeyh.name>2013-05-10 16:29:59 -0500
commit5d0476bf59674b39fa6bad7e4446b5c741181143 (patch)
tree67897681b96fb9e79990033822e1a645de1f96a7 /Utility/FileMode.hs
parent812f7d6c564e297b67850f2aa4751141a8f68e99 (diff)
stub out POSIX stuff
Diffstat (limited to 'Utility/FileMode.hs')
-rwxr-xr-x[-rw-r--r--]Utility/FileMode.hs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs
index b6bb579b5..cf9ec45a2 100644..100755
--- a/Utility/FileMode.hs
+++ b/Utility/FileMode.hs
@@ -5,6 +5,8 @@
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE CPP #-}
+
module Utility.FileMode where
import Common
@@ -17,6 +19,7 @@ import Foreign (complement)
{- Applies a conversion function to a file's mode. -}
modifyFileMode :: FilePath -> (FileMode -> FileMode) -> IO ()
modifyFileMode f convert = void $ modifyFileMode' f convert
+#if 0
modifyFileMode' :: FilePath -> (FileMode -> FileMode) -> IO FileMode
modifyFileMode' f convert = do
s <- getFileStatus f
@@ -25,6 +28,9 @@ modifyFileMode' f convert = do
when (new /= old) $
setFileMode f new
return old
+#else
+modifyFileMode' = error "modifyFileMode' TODO"
+#endif
{- Adds the specified FileModes to the input mode, leaving the rest
- unchanged. -}
@@ -33,7 +39,11 @@ addModes ms m = combineModes (m:ms)
{- Removes the specified FileModes from the input mode. -}
removeModes :: [FileMode] -> FileMode -> FileMode
+#if 0
removeModes ms m = m `intersectFileModes` complement (combineModes ms)
+#else
+removeModes = error "removeModes TODO"
+#endif
{- Runs an action after changing a file's mode, then restores the old mode. -}
withModifiedFileMode :: FilePath -> (FileMode -> FileMode) -> IO a -> IO a
@@ -44,43 +54,78 @@ withModifiedFileMode file convert a = bracket setup cleanup go
go _ = a
writeModes :: [FileMode]
+#if 0
writeModes = [ownerWriteMode, groupWriteMode, otherWriteMode]
+#else
+writeModes = []
+#endif
readModes :: [FileMode]
+#if 0
readModes = [ownerReadMode, groupReadMode, otherReadMode]
+#else
+readModes = []
+#endif
executeModes :: [FileMode]
+#if 0
executeModes = [ownerExecuteMode, groupExecuteMode, otherExecuteMode]
+#else
+executeModes = []
+#endif
{- Removes the write bits from a file. -}
preventWrite :: FilePath -> IO ()
+#if 0
preventWrite f = modifyFileMode f $ removeModes writeModes
+#else
+preventWrite _ = return ()
+#endif
{- Turns a file's owner write bit back on. -}
allowWrite :: FilePath -> IO ()
+#if 0
allowWrite f = modifyFileMode f $ addModes [ownerWriteMode]
+#else
+allowWrite _ = return ()
+#endif
{- Allows owner and group to read and write to a file. -}
groupWriteRead :: FilePath -> IO ()
+#if 0
groupWriteRead f = modifyFileMode f $ addModes
[ ownerWriteMode, groupWriteMode
, ownerReadMode, groupReadMode
]
+#else
+groupWriteRead _ = return ()
+#endif
+#if 0
checkMode :: FileMode -> FileMode -> Bool
checkMode checkfor mode = checkfor `intersectFileModes` mode == checkfor
+#endif
{- Checks if a file mode indicates it's a symlink. -}
isSymLink :: FileMode -> Bool
+#if 0
isSymLink = checkMode symbolicLinkMode
+#else
+isSymLink _ = False
+#endif
{- Checks if a file has any executable bits set. -}
isExecutable :: FileMode -> Bool
+#if 0
isExecutable mode = combineModes executeModes `intersectFileModes` mode /= 0
+#else
+isExecutable _ = False
+#endif
{- Runs an action without that pesky umask influencing it, unless the
- passed FileMode is the standard one. -}
noUmask :: FileMode -> IO a -> IO a
+#if 0
noUmask mode a
| mode == stdFileMode = a
| otherwise = bracket setup cleanup go
@@ -88,17 +133,28 @@ noUmask mode a
setup = setFileCreationMask nullFileMode
cleanup = setFileCreationMask
go _ = a
+#else
+noUmask _ a = a
+#endif
combineModes :: [FileMode] -> FileMode
+#if 0
combineModes [] = undefined
combineModes [m] = m
combineModes (m:ms) = foldl unionFileModes m ms
+#else
+combineModes _ = error "combineModes TODO"
+#endif
stickyMode :: FileMode
stickyMode = 512
isSticky :: FileMode -> Bool
+#if 0
isSticky = checkMode stickyMode
+#else
+isSticky _ = False
+#endif
setSticky :: FilePath -> IO ()
setSticky f = modifyFileMode f $ addModes [stickyMode]
@@ -110,6 +166,7 @@ setSticky f = modifyFileMode f $ addModes [stickyMode]
- as writeFile.
-}
writeFileProtected :: FilePath -> String -> IO ()
+#if 0
writeFileProtected file content = do
h <- openFile file WriteMode
void $ tryIO $
@@ -117,3 +174,6 @@ writeFileProtected file content = do
removeModes [groupReadMode, otherReadMode]
hPutStr h content
hClose h
+#else
+writeFileProtected = writeFile
+#endif