-- $permissions
- , Permissions(
- Permissions,
- readable, -- :: Permissions -> Bool
- writable, -- :: Permissions -> Bool
- executable, -- :: Permissions -> Bool
- searchable -- :: Permissions -> Bool
- )
+ , Permissions
+ , readable -- :: Permissions -> Bool
+ , writable -- :: Permissions -> Bool
+ , executable -- :: Permissions -> Bool
+ , searchable -- :: Permissions -> Bool
+ , setOwnerReadable
+ , setOwnerWritable
+ , setOwnerExecutable
+ , setOwnerSearchable
, getPermissions -- :: FilePath -> IO Permissions
, setPermissions -- :: FilePath -> Permissions -> IO ()
executable, searchable :: Bool
} deriving (Eq, Ord, Read, Show)
+setOwnerReadable :: Bool -> Permissions -> Permissions
+setOwnerReadable b p = p { readable = b }
+
+setOwnerWritable :: Bool -> Permissions -> Permissions
+setOwnerWritable b p = p { writable = b }
+
+setOwnerExecutable :: Bool -> Permissions -> Permissions
+setOwnerExecutable b p = p { executable = b }
+
+setOwnerSearchable :: Bool -> Permissions -> Permissions
+setOwnerSearchable b p = p { searchable = b }
+
{- |The 'getPermissions' operation returns the
permissions for the file or directory.
write_ok <- Posix.fileAccess name False True False
exec_ok <- Posix.fileAccess name False False True
stat <- Posix.getFileStatus name
- let is_dir = Posix.fileMode stat .&. Posix.directoryMode /= 0
+ let is_dir = Posix.isDirectory stat
return (
Permissions {
readable = read_ok,
else throw e
#else
stat <- Posix.getFileStatus dir
- if Posix.fileMode stat .&. Posix.directoryMode /= 0
+ if Posix.isDirectory stat
then return ()
else throw e
#endif
is_dir <- isDirectory st
#else
stat <- Posix.getSymbolicLinkStatus opath
- let is_dir = Posix.fileMode stat .&. Posix.directoryMode /= 0
+ let is_dir = Posix.isDirectory stat
#endif
if is_dir
then ioException (ioeSetErrorString
#else
withCString fpath $ \pInPath ->
allocaBytes long_path_size $ \pOutPath ->
- do c_realpath pInPath pOutPath
+ do throwErrnoPathIfNull "canonicalizePath" fpath $ c_realpath pInPath pOutPath
path <- peekCString pOutPath
#endif
return (normalise path)
(withFileStatus "doesDirectoryExist" name $ \st -> isDirectory st)
#else
(do stat <- Posix.getFileStatus name
- return (Posix.fileMode stat .&. Posix.directoryMode /= 0))
+ return (Posix.isDirectory stat))
#endif
`catch` ((\ _ -> return False) :: IOException -> IO Bool)
(withFileStatus "doesFileExist" name $ \st -> do b <- isDirectory st; return (not b))
#else
(do stat <- Posix.getFileStatus name
- return (Posix.fileMode stat .&. Posix.directoryMode == 0))
+ return (not (Posix.isDirectory stat)))
#endif
`catch` ((\ _ -> return False) :: IOException -> IO Bool)
modificationTime st
#else
stat <- Posix.getFileStatus name
- let realToInteger = round . realToFrac :: Real a => a -> Integer
- return (TOD (realToInteger (Posix.modificationTime stat)) 0)
+ let mod_time :: Posix.EpochTime
+ mod_time = Posix.modificationTime stat
+ dbl_time :: Double
+ dbl_time = realToFrac mod_time
+ return (TOD (round dbl_time) 0)
#endif
-
+ -- For info
+ -- round :: (RealFrac a, Integral b => a -> b
+ -- realToFrac :: (Real a, Fractional b) => a -> b
#endif /* __GLASGOW_HASKELL__ */
modificationTime :: Ptr CStat -> IO ClockTime
modificationTime stat = do
mtime <- st_mtime stat
- let realToInteger = round . realToFrac :: Real a => a -> Integer
- return (TOD (realToInteger (mtime :: CTime)) 0)
+ let dbl_time :: Double
+ dbl_time = realToFrac (mtime :: CTime)
+ return (TOD (round dbl_time) 0)
isDirectory :: Ptr CStat -> IO Bool
isDirectory stat = do