move sticky bit code into Utility.FileMode
Simplified it using existing functions. I doubt setSticky needs to return the FileMode; if it does for some reason, it can be changed to use modifyFileMode' Converted isSticky to a pure function for consistency with isSymlink. Note that the sticky bit of a file can be tested thus: isSticky . fileMode <$> getFileStatus file
This commit is contained in:
parent
39d60f3570
commit
1233417698
2 changed files with 13 additions and 18 deletions
|
@ -27,9 +27,6 @@ import Utility.FileMode
|
||||||
import Config
|
import Config
|
||||||
import qualified Option
|
import qualified Option
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import System.Posix.Types
|
|
||||||
import System.Posix.Files
|
|
||||||
import Data.Bits
|
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions options $ command "fsck" paramPaths seek
|
def = [withOptions options $ command "fsck" paramPaths seek
|
||||||
|
@ -322,20 +319,6 @@ badContentRemote remote key = do
|
||||||
return $ (if ok then "dropped from " else "failed to drop from ")
|
return $ (if ok then "dropped from " else "failed to drop from ")
|
||||||
++ Remote.name remote
|
++ Remote.name remote
|
||||||
|
|
||||||
isSticky :: String -> IO Bool
|
|
||||||
isSticky f = do
|
|
||||||
fs <- getFileStatus f
|
|
||||||
let mode = fileMode fs
|
|
||||||
return $ 0/= mode .&. 512
|
|
||||||
|
|
||||||
setSticky :: String -> IO FileMode
|
|
||||||
setSticky f = do
|
|
||||||
fs <- getFileStatus f
|
|
||||||
let mode = fileMode fs
|
|
||||||
let newmode = mode .|. 512
|
|
||||||
setFileMode f newmode
|
|
||||||
return newmode
|
|
||||||
|
|
||||||
updateMetadata :: Key -> Annex Bool
|
updateMetadata :: Key -> Annex Bool
|
||||||
updateMetadata key = do
|
updateMetadata key = do
|
||||||
file <- inRepo $ gitAnnexLocation key
|
file <- inRepo $ gitAnnexLocation key
|
||||||
|
|
|
@ -63,9 +63,12 @@ groupWriteRead f = modifyFileMode f $ addModes
|
||||||
, ownerReadMode, groupReadMode
|
, ownerReadMode, groupReadMode
|
||||||
]
|
]
|
||||||
|
|
||||||
|
checkMode :: FileMode -> FileMode -> Bool
|
||||||
|
checkMode checkfor mode = checkfor `intersectFileModes` mode == checkfor
|
||||||
|
|
||||||
{- Checks if a file mode indicates it's a symlink. -}
|
{- Checks if a file mode indicates it's a symlink. -}
|
||||||
isSymLink :: FileMode -> Bool
|
isSymLink :: FileMode -> Bool
|
||||||
isSymLink mode = symbolicLinkMode `intersectFileModes` mode == symbolicLinkMode
|
isSymLink = checkMode symbolicLinkMode
|
||||||
|
|
||||||
{- Checks if a file has any executable bits set. -}
|
{- Checks if a file has any executable bits set. -}
|
||||||
isExecutable :: FileMode -> Bool
|
isExecutable :: FileMode -> Bool
|
||||||
|
@ -88,3 +91,12 @@ combineModes :: [FileMode] -> FileMode
|
||||||
combineModes [] = undefined
|
combineModes [] = undefined
|
||||||
combineModes [m] = m
|
combineModes [m] = m
|
||||||
combineModes (m:ms) = foldl unionFileModes m ms
|
combineModes (m:ms) = foldl unionFileModes m ms
|
||||||
|
|
||||||
|
stickyMode :: FileMode
|
||||||
|
stickyMode = 512
|
||||||
|
|
||||||
|
isSticky :: FileMode -> Bool
|
||||||
|
isSticky = checkMode stickyMode
|
||||||
|
|
||||||
|
setSticky :: FilePath -> IO ()
|
||||||
|
setSticky f = modifyFileMode f $ addModes [stickyMode]
|
||||||
|
|
Loading…
Add table
Reference in a new issue