Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Hiroto/update system #231

Merged
merged 13 commits into from
Jul 26, 2019
Merged

Hiroto/update system #231

merged 13 commits into from
Jul 26, 2019

Conversation

HirotoShioi
Copy link
Contributor

#216
WIP

@HirotoShioi HirotoShioi added the wip Work In Progress label Jul 19, 2019
@HirotoShioi HirotoShioi requested review from erikd and ksaric as code owners July 19, 2019 06:40
Copy link
Contributor

@ksaric ksaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good direction, several comments to take a look at.

#endif

-- | Updater path, args, windows runner path, archive path
data UpdaterData = UpdaterData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can have UpdaterData for each platform?
Not sure why you have udWindowsPath.


updaterData :: UpdaterData
updaterData = case buildOS of
Windows -> UpdaterData "WindowsPath" ["Windows", "Args"] (Just "Window path") Nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use actual executables for the installers found here - #216 (comment)

removeFile updateArchivePath
return . Right $ ()
ExitFailure code -> return . Left $ UpdateFailed code
else return . Left $ UpdaterDoesNotExist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline after else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it possible to do return . Left . UpdaterDoesNotExist?
Just wondering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried, but compiler complained so its not possible.

updaterExists <- doesFileExist path
if updaterExists
then do
exitCode <- case mWindowPath of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should be optional.
An actual path should be there so it shouldn't be Maybe FilePath but an actual FilePath for an executable for each platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is optional since this field is not required when you're on Mac/Linux. You can have it mempty but that's kind of awkward.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know whether you are on Max/Linux or Windows so you don't need another check for that.

ExitFailure code -> return . Left $ UpdateFailed code
else return . Left $ UpdaterDoesNotExist
where
runCmd path args archive =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the types to an anonymous (or where/let) function when you are writing it to make it more clear.

whenJust (Just a) f = f a
whenJust Nothing _ = return ()

writeWindowsUpdaterRunner :: FilePath -> IO ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment where you copied this from and why.

@@ -3,8 +3,7 @@ module Cardano.Shell.Update.Types where
import Cardano.Prelude

import qualified Data.Map as M

import Test.QuickCheck
import Test.QuickCheck (Gen, choose, frequency, listOf1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, better.

@@ -36,6 +36,5 @@ extra-deps:
- containers-0.5.11.0
- libsystemd-journal-1.4.4


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

updaterData :: UpdaterData
updaterData = case buildOS of
Windows -> UpdaterData
"Installer.exe"
Copy link
Contributor

@ksaric ksaric Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent these after the constructor.

UpdaterData
    "Installer.exe"
    ...

This is hard to read.

Copy link
Contributor

@ksaric ksaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of smaller fixes.

@@ -38,6 +39,8 @@ import Data.X509.Extra (failIfReasons, genRSA256KeyPair,
main :: IO ()
main = do

-- _ <- runUpdater updaterData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.
We need a simple FilePath when somebody wants to call the runUpdater - then it will try to run the installer on the FilePath.

{ udPath :: !FilePath
, udArgs :: ![Text]
, udWindowsPath :: Maybe FilePath
, udArchivePath :: Maybe FilePath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this since you know whether it's a Windows platform or not.
You just need one of these.

withCreateProcess (proc path (args <> [archive]))
$ \_in _out _err ph -> waitForProcess ph

type RunCmdFunc = FilePath -> [String] -> FilePath -> IO ExitCode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inline this in the function type.

updaterExists <- doesFileExist path
if updaterExists
then do
exitCode <- case mWindowPath of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know whether you are on Max/Linux or Windows so you don't need another check for that.

Hiroto Shioi added 2 commits July 26, 2019 15:09
Copy link
Contributor

@ksaric ksaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ksaric ksaric merged commit 7d7cafc into master Jul 26, 2019
@ksaric ksaric deleted the hiroto/update-system branch July 26, 2019 08:24
@HirotoShioi HirotoShioi removed the wip Work In Progress label Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants