GTK: adjust to new LIB API and refactor file error handling
This restructures large parts of the GUI-wise error handling code and makes it more fine-grained, so the user can react appropriately to exceptions.
This commit is contained in:
@@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PackageImports #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# OPTIONS_HADDOCK ignore-exports #-}
|
||||
|
||||
|
||||
@@ -668,6 +669,33 @@ moveFile from to = do
|
||||
easyDelete from
|
||||
|
||||
|
||||
-- |Like `moveFile`, but overwrites the destination if it exists.
|
||||
--
|
||||
-- Does not follow symbolic links, but renames the symbolic link file.
|
||||
--
|
||||
-- Safety/reliability concerns:
|
||||
--
|
||||
-- * copy-delete fallback is inherently non-atomic
|
||||
-- * checks for destination file existence explicitly
|
||||
--
|
||||
-- Throws:
|
||||
--
|
||||
-- - `NoSuchThing` if source file does not exist
|
||||
-- - `PermissionDenied` if output directory cannot be written to
|
||||
-- - `PermissionDenied` if source directory cannot be opened
|
||||
-- - `SameFile` if destination and source are the same file (`FmIOException`)
|
||||
--
|
||||
-- Note: calls `rename` (but does not allow to rename over existing files)
|
||||
moveFileOverwrite :: Path Abs -- ^ file to move
|
||||
-> Path Abs -- ^ destination
|
||||
-> IO ()
|
||||
moveFileOverwrite from to = do
|
||||
throwSameFile from to
|
||||
exists <- (||) <$> doesFileExist to <*> doesDirectoryExist to
|
||||
writable <- isWritable $ P.dirname to
|
||||
when (exists && writable) (easyDelete to)
|
||||
moveFile from to
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user