Update ZfsDevices.hs
This commit is contained in:
parent
c4ceaadd15
commit
4f42f6f687
1 changed files with 22 additions and 4 deletions
|
|
@ -1,16 +1,34 @@
|
|||
-- Copyright © 2025 Hashirama Senju
|
||||
|
||||
|
||||
import System.Zfs.Zpool
|
||||
import System.Zfs.Types
|
||||
import System.Zfs
|
||||
import Control.Monad.IO.Class
|
||||
import System.Process (callCommand)
|
||||
import System.Process (createProcess, shell, waitForProcess, CreateProcess(..), StdStream(..))
|
||||
import System.IO (openTempFile, hClose, IOMode(WriteMode))
|
||||
import System.Directory (getTemporaryDirectory, removeFile)
|
||||
import Control.Exception (bracket)
|
||||
|
||||
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
|
||||
|
||||
forZpools_ $ \zpool -> do
|
||||
our_pools <- getZpools
|
||||
|
||||
forZpools_ $ \zpool -> do
|
||||
nm <- getZpoolName zpool
|
||||
liftIO $ putStrLn ("Pool: "++nm)
|
||||
vdevs <- getVdevs zpool
|
||||
|
|
@ -23,7 +41,7 @@ main' = do
|
|||
main :: IO ()
|
||||
main = do
|
||||
|
||||
callCommand "zpool import -a" -- should make a ffi function for it
|
||||
callCommandSilently "zpool import -a -N" -- detection, a ffi would be more elegant
|
||||
res <- runZfs main'
|
||||
case res of
|
||||
Left e -> print e
|
||||
|
|
|
|||
Loading…
Reference in a new issue