LIB: add delete file/dir
This commit is contained in:
parent
0f1301622b
commit
25f620ad75
@ -1,9 +1,6 @@
|
|||||||
{-# OPTIONS_HADDOCK ignore-exports #-}
|
{-# OPTIONS_HADDOCK ignore-exports #-}
|
||||||
|
|
||||||
module IO.File (
|
module IO.File where
|
||||||
openFile
|
|
||||||
, executeFile
|
|
||||||
) where
|
|
||||||
|
|
||||||
|
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
@ -18,9 +15,12 @@ import Control.Monad
|
|||||||
import IO.Error
|
import IO.Error
|
||||||
import System.Directory
|
import System.Directory
|
||||||
(
|
(
|
||||||
doesFileExist
|
doesDirectoryExist
|
||||||
, getPermissions
|
, doesFileExist
|
||||||
, executable
|
, executable
|
||||||
|
, getPermissions
|
||||||
|
, removeDirectory
|
||||||
|
, removeFile
|
||||||
)
|
)
|
||||||
import System.FilePath.Posix
|
import System.FilePath.Posix
|
||||||
(
|
(
|
||||||
@ -33,6 +33,39 @@ import System.Process
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
data FileOperation = Copy
|
||||||
|
| Move
|
||||||
|
| Delete
|
||||||
|
| Open
|
||||||
|
| Execute
|
||||||
|
|
||||||
|
|
||||||
|
-- |Deletes the given file.
|
||||||
|
--
|
||||||
|
-- This will throw an exception if the filepath is not absolute
|
||||||
|
-- or the file does not exist.
|
||||||
|
--
|
||||||
|
-- It also throws exceptions from `removeFile`.
|
||||||
|
-- TODO: threaded, shouldn't block the GUI
|
||||||
|
deleteFile :: FilePath -> IO ()
|
||||||
|
deleteFile fp = do
|
||||||
|
fileSanityThrow fp
|
||||||
|
removeFile fp
|
||||||
|
|
||||||
|
|
||||||
|
-- |Deletes the given directory.
|
||||||
|
--
|
||||||
|
-- This will throw an exception if the filepath is not absolute
|
||||||
|
-- or the directory does not exist.
|
||||||
|
--
|
||||||
|
-- It also throws exceptions from `removeDirectory`.
|
||||||
|
-- TODO: threaded, shouldn't block the GUI
|
||||||
|
deleteDir :: FilePath -> IO ()
|
||||||
|
deleteDir fp = do
|
||||||
|
dirSanityThrow fp
|
||||||
|
removeDirectory fp
|
||||||
|
|
||||||
|
|
||||||
-- |Opens a file appropriately by invoking xdg-open.
|
-- |Opens a file appropriately by invoking xdg-open.
|
||||||
--
|
--
|
||||||
-- This will throw an exception if the filepath is not absolute
|
-- This will throw an exception if the filepath is not absolute
|
||||||
@ -66,3 +99,12 @@ fileSanityThrow fp = do
|
|||||||
unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
||||||
exists <- doesFileExist fp
|
exists <- doesFileExist fp
|
||||||
unless exists (throw $ FileDoesNotExist fp)
|
unless exists (throw $ FileDoesNotExist fp)
|
||||||
|
|
||||||
|
|
||||||
|
-- Throws an exception if the filepath is not absolute
|
||||||
|
-- or the dir does not exist.
|
||||||
|
dirSanityThrow :: FilePath -> IO ()
|
||||||
|
dirSanityThrow fp = do
|
||||||
|
unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
||||||
|
exists <- doesDirectoryExist fp
|
||||||
|
unless exists (throw $ FileDoesNotExist fp)
|
||||||
|
Loading…
Reference in New Issue
Block a user