summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will@willthompson.co.uk>2015-04-22 08:53:22 +0100
committerWill Thompson <will@willthompson.co.uk>2015-04-22 08:53:22 +0100
commite9d959f2ac1c014f81039c1513a387778949a24d (patch)
treefa76d79a5f545c18610cadea967cd2d14d6d3c87
parentdd0d0e08c2727d8fb768ae483242a85115e18c7b (diff)
Don't crash when saving logs to a FS other than $HOME
renameFile can in practice only cope with same-filesystem renames. GIO's fileMove can fall back to copy + delete.
-rw-r--r--Bustle/UI.hs20
-rw-r--r--bustle.cabal1
2 files changed, 18 insertions, 3 deletions
diff --git a/Bustle/UI.hs b/Bustle/UI.hs
index a118ee1..09540c2 100644
--- a/Bustle/UI.hs
+++ b/Bustle/UI.hs
@@ -63,7 +63,7 @@ import System.FilePath ( splitFileName, takeFileName, takeDirectory
, dropExtension, dropTrailingPathSeparator
, (</>), (<.>)
)
-import System.Directory (renameFile)
+import System.GIO.File.File (fileFromParseName, fileMove, FileCopyFlags(..))
type B a = Bustle BConfig BState a
@@ -275,8 +275,22 @@ showSaveDialog wi savedCb = do
tempFileName = takeFileName tempFilePath
recorderChooseFile tempFileName mwindow $ \newFilePath -> do
- -- TODO: crashes if these are on two different filesystems, sigh
- renameFile tempFilePath newFilePath
+ let tempFile = fileFromParseName tempFilePath
+ let newFile = fileFromParseName newFilePath
+
+ C.catch (fileMove tempFile newFile [FileCopyOverwrite] Nothing Nothing) $ \(GError _ _ msg) -> do
+ d <- messageDialogNew mwindow [DialogModal] MessageError ButtonsOk (__ "Couldn't save log")
+ let secondary :: String
+ secondary = printf
+ (__ "Error: <i>%s</i>\n\n\
+ \You might want to manually recover the log from the temporary file at\n\
+ \<tt>%s</tt>") (toString msg) tempFilePath
+ messageDialogSetSecondaryMarkup d secondary
+ widgetShowAll d
+ d `after` response $ \_ -> do
+ widgetDestroy d
+ return ()
+
widgetSetSensitivity (wiSave wi) False
wiSetLogDetails wi (SingleLog newFilePath)
savedCb
diff --git a/bustle.cabal b/bustle.cabal
index b440c92..cc95d54 100644
--- a/bustle.cabal
+++ b/bustle.cabal
@@ -109,6 +109,7 @@ Executable bustle
, directory
, filepath
, glib
+ , gio
, gtk3
, hgettext >= 0.1.5
, mtl