darcs-2.18.5: a distributed, interactive, smart revision control system

Safe Haskell | None
Language | Haskell2010

Darcs.Util.File

Contents

- Files and directories
- Fetching files
- Backup
- Temporary files

Synopsis

- getFileStatus :: FilePath -> IO (Maybe FileStatus)
- doesDirectoryReallyExist :: FilePath -> IO Bool
- removeFileMayNotExist :: FilePathLike p => p -> IO ()
- getRecursiveContents :: FilePath -> IO [FilePath]
- getRecursiveContentsFullPath :: FilePath -> IO [FilePath]
- copyTree :: FilePath -> FilePath -> IO ()
- fetchFilePS :: String -> Cachable -> IO ByteString
- fetchFileLazyPS :: String -> Cachable -> IO ByteString
- gzFetchFilePS :: String -> Cachable -> IO ByteString
- speculateFileOrUrl :: String -> FilePath -> IO ()
- copyFileOrUrl :: String -> String -> FilePath -> Cachable -> IO ()
- data Cachable
  - = Cachable
  - | Uncachable
  - | MaxAge !CInt
- backupByRenaming :: FilePath -> IO ()
- backupByCopying :: FilePath -> IO ()
- withTemp :: (FilePath -> IO a) -> IO a
- withOpenTemp :: ((Handle, FilePath) -> IO a) -> IO a

# Files and directories

getFileStatus :: FilePath -> IO (Maybe FileStatus) #

Badly named, since it is actually `getSymbolicLinkStatus`, with all `IOError`s turned into `Nothing`.

doesDirectoryReallyExist :: FilePath -> IO Bool #

Whether a path is an existing directory, but not a symlink to one.

removeFileMayNotExist :: FilePathLike p => p -> IO () #

Variant of `removeFile` that doesn't throw exception when file does not exist.

getRecursiveContents :: FilePath -> IO [FilePath] #

Return all files under given directory that aren't directories.

getRecursiveContentsFullPath :: FilePath -> IO [FilePath] #

Return all files under given directory that aren't directories. Unlike `getRecursiveContents` this function returns the full path.

copyTree :: FilePath -> FilePath -> IO () #

Recursively copy a directory, where the target directory is supposed to already exist.

# Fetching files

fetchFilePS :: String -> Cachable -> IO ByteString #

`fetchFilePS fileOrUrl cache` returns the content of its argument (either a file or an URL). If it has to download an url, then it will use a cache as required by its second argument.

We always use default remote darcs, since it is not fatal if the remote darcs does not exist or is too old -- anything that supports transfer-mode should do, and if not, we will fall back to SFTP or SCP.

fetchFileLazyPS :: String -> Cachable -> IO ByteString #

`fetchFileLazyPS fileOrUrl cache` lazily reads the content of its argument (either a file or an URL). Warning: this function may constitute a fd leak; make sure to force consumption of file contents to avoid that. See "fetchFilePS" for details.

gzFetchFilePS :: String -> Cachable -> IO ByteString #

Like `fetchFilePS` but transparently handle gzip compressed files.

speculateFileOrUrl :: String -> FilePath -> IO () #

Initiate background file download for the given file path or URL to the given location.

copyFileOrUrl #

Arguments

:: String | remote darcs executable
-> String | path representing the origin file or URL
-> FilePath | destination path
-> Cachable | tell whether file to copy is cachable
-> IO () |

Very much darcs-specific copying procedure. For local files it tries to hard-link, falling back to normal copy if it fails. Remote URLs are downloaded using either HTTP or SSH. For SSH, this tries to use the given remote darcs command to invoke it's transfer-mode command.

data Cachable #

Constructors

Cachable |
Uncachable |
MaxAge !CInt |

#### Instances

Instances details

Show Cachable # |
Instance details Defined in Darcs.Util.HTTP Methods showsPrec :: Int -> Cachable -> ShowS # show :: Cachable -> String # showList :: [Cachable] -> ShowS #
Eq Cachable # |
Instance details Defined in Darcs.Util.HTTP Methods (==) :: Cachable -> Cachable -> Bool # (/=) :: Cachable -> Cachable -> Bool #

# Backup

backupByRenaming :: FilePath -> IO () #

backupByCopying :: FilePath -> IO () #

# Temporary files

withTemp :: (FilePath -> IO a) -> IO a #

Invoke the given action on a file that is temporarily created in the current directory, and removed afterwards.

withOpenTemp :: ((Handle, FilePath) -> IO a) -> IO a #

Invoke the given action on a file that is temporarily created and opened in the current directory, and closed and removed afterwards.