]> woffs.de Git - fd/haskell-amqp-utils.git/commitdiff
removeSentFileIfRequested
authorFrank Doepper <[email protected]>
Sat, 30 Jan 2021 18:21:01 +0000 (19:21 +0100)
committerFrank Doepper <[email protected]>
Sat, 30 Jan 2021 21:59:06 +0000 (22:59 +0100)
Network/AMQP/Utils/Options.hs
agitprop.hs

index 6654da2815c5d7f19014250009c845c4274a2184..0ee7bf4525622dc2e71329d6b586a4a63e3b7fdd 100644 (file)
@@ -69,6 +69,7 @@ data Args =
     , connect_timeout :: Int
     , simple          :: Bool
     , cleanupTmpFile  :: Bool
+    , removeSentFile  :: Bool
     }
 
 instance Default Args where
@@ -120,6 +121,7 @@ instance Default Args where
       600
       False
       False
+      False
 
 -- | all options
 allOptions :: [(String, OptDescr (Args -> Args))]
@@ -300,6 +302,12 @@ allOptions =
         ["suffix"]
         (ReqArg (\s o -> o {suffix = s : (suffix o)}) "SUFFIX")
         "Allowed file suffixes in hotfolder mode")
+  , ( "a"
+    , Option
+        ['u']
+        ["remove"]
+        (NoArg (\o -> o {removeSentFile = not (removeSentFile o)}))
+        ("Toggle removal of sent file (default: " ++ show (removeSentFile def) ++ ")"))
   , ( "a"
     , Option
         ['m']
index e2d45a0d5b466a33a4420e156527ade4c101d7c6..9715e6944180cad41fce6c52836acced70ec3506 100644 (file)
@@ -22,6 +22,7 @@ import           Network.AMQP.Utils.Connection
 import           Network.AMQP.Utils.Helpers
 import           Network.AMQP.Utils.Options
 import           Paths_amqp_utils              (version)
+import           System.Directory              (removeFile)
 import           System.Environment
 import           System.Exit
 import           System.INotify
@@ -145,7 +146,7 @@ handleFile f [] x =
     (\e -> printparam "exception in handleFile" (e :: X.SomeException))
 
 -- | Publish one message with our settings
-publishOneMsg' :: Channel -> Args -> Maybe String -> BL.ByteString -> IO ()
+publishOneMsg' :: Channel -> Args -> Maybe FilePath -> BL.ByteString -> IO ()
 publishOneMsg' c a fn f = do
   printparam "sending" fn
   (mtype, mencoding) <-
@@ -181,9 +182,13 @@ publishOneMsg' c a fn f = do
       , msgHeaders = substheader (fnheader a) fn $ msgheader a
       } >>=
     printparam "sent"
+  removeSentFileIfRequested (removeSentFile a) fn
   where
     substheader ::
          [String] -> Maybe String -> Maybe FieldTable -> Maybe FieldTable
     substheader (s:r) (Just fname) old =
       substheader r (Just fname) (addheader old (s ++ "=" ++ fname))
     substheader _ _ old = old
+    removeSentFileIfRequested False _           = return ()
+    removeSentFileIfRequested True Nothing      = return ()
+    removeSentFileIfRequested True (Just fname) = printparam "removing" fname >> removeFile fname
don't click here