Update ZfsDevices.hs

This commit is contained in:
千住柱間 2025-02-19 04:01:35 +00:00
commit 620dc5a47d

View file

@ -5,24 +5,9 @@ import System.Zfs.Zpool
import System.Zfs.Types
import System.Zfs
import Control.Monad.IO.Class
import System.Process (createProcess, shell, waitForProcess, CreateProcess(..), StdStream(..))
import System.IO (openTempFile, hClose, IOMode(WriteMode))
import System.Directory (getTemporaryDirectory, removeFile)
import Control.Exception (bracket)
import System.Process (callCommand)
import Control.Concurrent (threadDelay)
callCommandSilently :: String -> IO ()
callCommandSilently cmd = do
tempDir <- getTemporaryDirectory
let tempFile = tempDir ++ "/temp_output.log"
bracket
(openTempFile tempDir "temp_output.log")
(\(path, handle) -> hClose handle >> removeFile path)
(\(path, handle) -> do
let process = (shell cmd) { std_out = UseHandle handle, std_err = UseHandle handle }
(_, _, _, ph) <- createProcess process
waitForProcess ph
return ()
)
main' :: Zfs ()
main' = do
@ -41,8 +26,9 @@ main' = do
main :: IO ()
main = do
callCommandSilently "zpool import -a -N" -- detection, a ffi would be more elegant
callCommand "zpool import -a -N > /dev/null 2>&1" -- detection, a ffi would be more elegant
threadDelay (10 * 1000000)
res <- runZfs main'
case res of
Left e -> print e
Right n -> return ()
Right n -> return ()