]> woffs.de Git - fd/haskell-amqp-utils.git/commitdiff
setCurrentDirectory
authorFrank Doepper <[email protected]>
Sun, 31 Jan 2021 17:01:13 +0000 (18:01 +0100)
committerFrank Doepper <[email protected]>
Sun, 31 Jan 2021 17:01:13 +0000 (18:01 +0100)
fixes handling of .* files/dirs in hotfolder mode

agitprop.hs

index fbc8efc796932a2dfe79840c8df75d9829328798..617152bce12e3f467ad442c7ee7956047360036c 100644 (file)
@@ -1,4 +1,5 @@
-{-# LANGUAGE CPP #-}
+{-# LANGUAGE CPP               #-}
+{-# LANGUAGE OverloadedStrings #-}
 
 -- generic AMQP publisher
 import           Control.Concurrent
@@ -61,20 +62,17 @@ main = do
   X.catch
     (if isDir
        then do
+         setCurrentDirectory (inputFile args)
          if (initialScan args)
-           then getDirectoryContents (inputFile args) >>= mapM_ (\fn -> handleFile publishOneMsg (suffix args) ((inputFile args) ++ "/" ++ fn))
+           then getDirectoryContents "." >>= mapM_ (\fn -> handleFile publishOneMsg (suffix args) fn)
            else return()
          inotify <- initINotify
          wd <-
            addWatch
              inotify
              [CloseWrite, MoveIn]
-#if MIN_VERSION_hinotify(0,3,10)
-             (BS.pack (inputFile args))
-#else
-             (inputFile args)
-#endif
-             (handleEvent publishOneMsg (suffix args) (inputFile args))
+             "."
+             (handleEvent publishOneMsg (suffix args))
          hr $ "BEGIN watching " ++ (inputFile args)
          _ <- forever $ threadDelay 1000000
          removeWatch wd
@@ -120,20 +118,19 @@ confirmCallback (deliveryTag, isAll, ackType) =
 handleEvent ::
      (Maybe String -> BL.ByteString -> IO ())
   -> [String]
-  -> String
   -> Event
   -> IO ()
 -- just handle closewrite and movedin events
 #if MIN_VERSION_hinotify(0,3,10)
-handleEvent func suffixes path (Closed False (Just fileName) True) =
-  handleFile func suffixes (path ++ "/" ++ (BS.unpack fileName))
-handleEvent func suffixes path (MovedIn False fileName _) =
-  handleFile func suffixes (path ++ "/" ++ (BS.unpack fileName))
+handleEvent func suffixes (Closed False (Just fileName) True) =
+  handleFile func suffixes (BS.unpack fileName)
+handleEvent func suffixes (MovedIn False fileName _) =
+  handleFile func suffixes (BS.unpack fileName)
 #else
-handleEvent func suffixes path (Closed False (Just fileName) True) = handleFile func suffixes (path ++ "/" ++ fileName)
-handleEvent func suffixes path (MovedIn False fileName _) = handleFile func suffixes (path ++ "/" ++ fileName)
+handleEvent func suffixes (Closed False (Just fileName) True) = handleFile func suffixes fileName
+handleEvent func suffixes (MovedIn False fileName _) = handleFile func suffixes fileName
 #endif
-handleEvent _ _ _ = return ()
+handleEvent _ _ _ = return ()
 
 -- | Hotfolder file handler
 handleFile ::
don't click here