Commits

Colin Woodbury  committed 435dd83

Altered `--hotedit` functionality - Fixes #49

- `--hotedit` will now prompt before dependency checks.
- For AUR packages that appear _after_ the dependency checks, the user
will be prompted before the building of each one. This is the same as
`--hotedit`'s old functionality.

  • Participants
  • Parent commits 716646c

Comments (0)

Files changed (2)

 
 module Aura.A where
 
-import Control.Monad (unless, liftM)
+import Control.Monad (when, unless, liftM)
 import Data.List ((\\), nub, sort)
 import Text.Regex.PCRE ((=~))
 import System.Exit (ExitCode)
   reportIgnoredPackages lang ignored
   (forPacman,aurPkgNames,nonPkgs) <- divideByPkgType toInstall
   reportNonPackages lang nonPkgs
+  notify ss installPackagesMsg7
   aurPackages <- mapM makeAURPkg aurPkgNames
-  unless (not $ diffPkgbuilds ss) $ reportPkgbuildDiffs ss aurPackages
+  when (diffPkgbuilds ss) $ reportPkgbuildDiffs ss aurPackages
+  aurPackages <- checkHotEdit ss aurPackages
   notify ss installPackagesMsg5
-  results     <- getDepsToInstall ss aurPackages
+  results <- getDepsToInstall ss aurPackages
   case results of
     Left errors -> do
       printList red noColour (installPackagesMsg1 lang) errors
 
 buildAndInstallDep :: Settings -> [String] -> AURPkg -> IO ExitCode
 buildAndInstallDep ss pacOpts pkg =
-  buildPackages ss [pkg] ?>>=
-  installPkgFiles ss (["--asdeps"] ++ pacOpts) . fromJust
-               
+  (checkHotEdit ss [pkg] >>= buildPackages ss) ?>>=
+  installPkgFiles ss ("--asdeps" : pacOpts) . fromJust
+
+checkHotEdit :: Settings -> [AURPkg] -> IO [AURPkg]
+checkHotEdit ss pkgs | mayHotEdit ss = hotEdit ss pkgs
+                     | otherwise     = return pkgs
+
 upgradeAURPkgs :: Settings -> [String] -> [String] -> IO ExitCode
 upgradeAURPkgs ss pacOpts pkgs = do
   notify ss upgradeAURPkgsMsg1

File Aura/Build.hs

 -- Kinda ugly.
 -- Perform the actual build. Fails elegantly when build fails occur.
 build :: Settings -> AURPkg -> IO (Either ErrMsg FilePath)
-build settings pkg = do
+build ss pkg = do
   currDir <- pwd
   getSourceCode (pkgNameOf pkg) user currDir
-  checkHotEdit settings $ pkgNameOf pkg
+  when (mayHotEdit ss) $ overwritePB pkg
   (exitStatus,pkgName,output) <- makepkg' user
   if didProcessFail exitStatus
      then return $ Left output
      else do
-       path <- moveToCache (cachePathOf settings) pkgName
+       path <- moveToCache (cachePathOf ss) pkgName
        cd currDir
        return $ Right path
     where makepkg'   = if toSuppress then makepkgQuiet else makepkgVerbose
-          toSuppress = suppressMakepkg settings
-          user       = getTrueUser $ environmentOf settings
+          toSuppress = suppressMakepkg ss
+          user       = getTrueUser $ environmentOf ss
 
 getSourceCode :: String -> String -> FilePath -> IO ()
 getSourceCode pkgName user currDir = do
   cd sourceDir
 
 -- Allow the user to edit the PKGBUILD if they asked to do so.
-checkHotEdit :: Settings -> String -> IO ()
-checkHotEdit settings pkgName = return (mayHotEdit settings) ?>> do
-    optionalPrompt (mustConfirm settings) msg ?>> openEditor editor "PKGBUILD"
-    where msg    = checkHotEditMsg1 (langOf settings) pkgName
-          editor = getEditor $ environmentOf settings
+hotEdit :: Settings -> [AURPkg] -> IO [AURPkg]
+hotEdit ss pkgs = withTempDir "hotedit" . flip mapM pkgs $ \p -> do
+  answer <- optionalPrompt (mustConfirm ss) (msg p)
+  if not answer
+     then return p
+     else do
+       let filename = pkgNameOf p ++ "-PKGBUILD"
+       writeFile filename $ pkgbuildOf p
+       openEditor editor filename
+       new <- readFile filename
+       return $ AURPkg (pkgNameOf p) (versionOf p) new
+    where msg p  = checkHotEditMsg1 (langOf ss) $ pkgNameOf p
+          editor = getEditor $ environmentOf ss
+
+overwritePB :: AURPkg -> IO ()
+overwritePB pkg = writeFile "PKGBUILD" $ pkgbuildOf pkg
 
 -- Inform the user that building failed. Ask them if they want to
 -- continue installing previous packages that built successfully.