diff options
author | Joey Hess <joey@kitenet.net> | 2012-09-25 13:30:32 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-09-25 13:33:13 -0400 |
commit | 19043fb8013180c0ac18e45129e0f20cb3ea7ff0 (patch) | |
tree | 80badf026584e6c44e7604a487475f0d70f9be11 /Utility | |
parent | 198beb11348ec1485cadd3a8a576b3b68d9170ee (diff) |
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
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/FileMode.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index 353de7b92..c742c690b 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -63,9 +63,12 @@ groupWriteRead f = modifyFileMode f $ addModes , ownerReadMode, groupReadMode ] +checkMode :: FileMode -> FileMode -> Bool +checkMode checkfor mode = checkfor `intersectFileModes` mode == checkfor + {- Checks if a file mode indicates it's a symlink. -} isSymLink :: FileMode -> Bool -isSymLink mode = symbolicLinkMode `intersectFileModes` mode == symbolicLinkMode +isSymLink = checkMode symbolicLinkMode {- Checks if a file has any executable bits set. -} isExecutable :: FileMode -> Bool @@ -88,3 +91,12 @@ combineModes :: [FileMode] -> FileMode combineModes [] = undefined combineModes [m] = m 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] |