https://hasufell.github.io/posts/2022-06-29-fixing-haskell-filepaths.html
import System.Directory (removeFile)
import System.Environment (getEnvironment)
import System.Exit
-import System.FilePath.Posix.ByteString (RawFilePath)
import System.IO
+import System.Posix.ByteString (RawFilePath)
import System.Posix.IO.ByteString
import System.Process
firstInputFile :: [(RawFilePath,String,String)] -> RawFilePath
firstInputFile [] = "-"
firstInputFile ((x,_,_):_) = x
-
--- | read RawFilePath to Lazy ByteString
-readFileRawLazy :: RawFilePath -> IO BL.ByteString
-readFileRawLazy path = do
- h <- openFd path ReadOnly defaultFlags >>= fdToHandle
- hSetBinaryMode h True
- BL.hGetContents h
- where
- defaultFlags = defaultFileFlags { noctty = True }
import Network.Socket (PortNumber)
import Paths_amqp_utils (version)
import System.Console.GetOpt
-import System.FilePath.Posix.ByteString (RawFilePath)
+import System.Posix.ByteString (RawFilePath)
portnumber :: Args -> PortNumber
portnumber a
import Network.AMQP.Utils.Helpers
import Network.AMQP.Utils.Options
import Paths_amqp_utils (version)
-import qualified RawFilePath.Directory as RD
+import qualified System.Directory.OsPath as DO
import System.Environment
import System.Exit
-import System.FilePath.Posix.ByteString
#if linux_HOST_OS
import System.INotify
#endif
-import qualified System.Posix.Files.ByteString as F
+import System.Posix.ByteString (RawFilePath)
+import qualified System.Posix.Files.ByteString as FB
+import qualified System.Posix.Files.PosixString as FP
+import qualified System.OsPath as OS
+import qualified System.File.OsPath as FOS
main :: IO ()
main = do
isDir <-
if inputFile' == "-"
then return False
- else F.getFileStatus inputFile' >>= return . F.isDirectory
+ else FB.getFileStatus inputFile' >>= return . FB.isDirectory
let publishOneMsg =
publishOneMsg' chan args {removeSentFile = removeSentFile args && isDir}
if isDir
messageFile <-
if inputFile' == "-"
then BL.getContents
- else readFileRawLazy inputFile'
+ else OS.encodeUtf (BS.unpack inputFile') >>= FOS.readFile
if (lineMode args)
then mapM_ (publishOneMsg (currentExchange args) (rKey args) Nothing) (BL.lines messageFile)
else publishOneMsg (currentExchange args) (rKey args) (Just (inputFile')) messageFile
(handleEvent (publishOneMsg exchange rkey) (suffix args) folder)
hr "BEGIN watching"
if (initialScan args)
- then RD.listDirectory folder >>=
- mapM_ (\fn -> handleFile (publishOneMsg exchange rkey) (suffix args) (folder </> fn))
- else return ()
+ then DO.listDirectory folder >>=
+ mapM_ (\fn -> handleFile (publishOneMsg exchange rkey) (suffix args) (folder OS.</> fn))
+ else return ()
return (wd,folder)
#endif
(Maybe RawFilePath -> BL.ByteString -> IO ()) -> [BS.ByteString] -> RawFilePath -> Event -> IO ()
-- just handle closewrite and movedin events
handleEvent func suffixes folder (Closed False (Just fileName) True) =
- handleFile func suffixes (folder </> fileName)
+ handleFile func suffixes (folder OS.</> fileName)
handleEvent func suffixes folder (MovedIn False fileName _) =
- handleFile func suffixes (folder </> fileName)
+ handleFile func suffixes (folder OS.</> fileName)
handleEvent _ _ _ _ = return ()
-- | Hotfolder file handler
else return ()
handleFile func [] fileName =
X.catch
- (readFileRawLazy fileName >>= func (Just fileName))
+ (FOS.readFile fileName >>= func (Just fileName))
(\e -> printparam "exception while processing" fileName >> printparam "exception in handleFile" (e :: X.IOException))
#endif
, msgPriority = prio a
, msgCorrelationID = corrid a
, msgExpiration = msgexp a
- , msgHeaders = substheader (fnheader a) (fmap takeFileName fn) $ msgheader a
+ , msgHeaders = substheader (fnheader a) (fmap OS.takeFileName fn) $ msgheader a
} >>=
printparam "sent"
removeSentFileIfRequested (removeSentFile a) (moveSentFileTo a) fn
removeSentFileIfRequested False _ _ = return ()
removeSentFileIfRequested True _ Nothing = return ()
removeSentFileIfRequested True Nothing (Just fname) =
- printparam "removing" fname >> RD.removeFile fname
+ printparam "removing" fname >> DO.removeFile fname
removeSentFileIfRequested True (Just path) (Just fname) =
printparam "moving" [fname,"to",path] >>
- F.rename fname (replaceDirectory fname ((takeDirectory fname) </> path))
+ FP.rename fname (OS.replaceDirectory fname ((OS.takeDirectory fname) OS.</> path))
addheader' :: Maybe FieldTable -> String -> BS.ByteString -> Maybe FieldTable
addheader' Nothing k v =
Just $ FieldTable $ M.singleton (T.pack k) (FVString v)
directory,
bytestring,
utf8-string,
- filepath-bytestring,
+ filepath >= 1.4.100,
+ file-io,
crypton-x509-system,
network > 2.6,
tls >= 1.7.0,
time,
process,
directory,
- filepath,
+ filepath >= 1.4.100,
+ file-io,
bytestring,
utf8-string,
- rawfilepath,
- filepath-bytestring,
crypton-x509-system,
network > 2.6,
tls >= 1.7.0,
directory,
bytestring,
utf8-string,
- filepath-bytestring,
+ filepath >= 1.4.100,
+ file-io,
crypton-x509-system,
network > 2.6,
tls >= 1.7.0,
- amqp >=0.22.2,
+ amqp >= 0.22.2,
unix >= 2.8
ghc-options: -threaded -Wall
directory,
bytestring,
utf8-string,
- filepath-bytestring,
+ filepath >= 1.4.100,
+ file-io,
crypton-x509-system,
network > 2.6,
tls >= 1.7.0,
{ lib, mkDerivation, amqp, base, bytestring, crypton-connection, containers
, data-default-class, process, text, time, tls, crypton-x509-system, unix
-, hinotify, magic, network, directory, utf8-string, filepath
-, rawfilepath, filepath-bytestring
+, hinotify, magic, network, directory, utf8-string, filepath, file-io
}:
mkDerivation {
executableHaskellDepends = [
amqp base bytestring crypton-connection containers data-default-class
process text time tls crypton-x509-system unix hinotify magic network
- directory utf8-string filepath rawfilepath filepath-bytestring
+ directory utf8-string filepath file-io
];
description = "AMQP toolset for the command line";
license = lib.licenses.gpl3Only;
# thank https://magnus.therning.org/2022-03-13-simple-nix-flake-for-haskell-development.html !
{
inputs = {
- nixpkgs.url = "nixpkgs/haskell-updates";
+ nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "flake-utils";
};
amqp = hl.dontCheck super.amqp_0_22_2;
tls = super.tls_1_7_0;
crypton-connection = super.crypton-connection.override { inherit tls; };
- rawfilepath = hl.overrideCabal super.rawfilepath {
- src = pkgs.fetchFromGitHub {
- owner = "georgefst";
- repo = "rawfilepath";
- rev = "044079fa0c3a407037be9086fab92f1209dfb1a8";
- hash = "sha256-2LFMLjhm6lLzXTditN0pi9R4QKg0zdBsDOPhcQUD1lQ=";
- };
- };
};
modifier = (t.flip t.pipe) [
hl.dontHaddock
import Control.Concurrent
import qualified Control.Exception as X
import Control.Monad
+import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Text as T
import Data.Time
import System.Environment
import System.Exit
import System.IO
+import qualified System.File.OsPath as FOS
+import qualified System.OsPath as OS
main :: IO ()
main = do
message <-
if inputFile' == "-"
then BL.getContents
- else readFileRawLazy inputFile'
+ else OS.encodeUtf (BS.unpack inputFile') >>= FOS.readFile
printparam "output file" $ outputFile args
h <-
if outputFile args == "-"
#
# SPDX-License-Identifier: GPL-3.0-only
-resolver: nightly-2023-07-19
+resolver: nightly-2023-08-21
flags: {}
extra-package-dbs: []
packages:
nix:
packages: [ file ]
extra-deps:
-- amqp-0.22.2
-- git: https://github.com/georgefst/rawfilepath/
- commit: 044079fa0c3a407037be9086fab92f1209dfb1a8
+- file-io-0.1.0.1