66 "log"
77 "os"
88 "path"
9+ "path/filepath"
910 "runtime"
1011)
1112
@@ -37,9 +38,9 @@ func genInfoNode(r *Runtime) map[string]string {
3738
3839 return map [string ]string {
3940 "nodeFileName" : nodeFileName ,
40- "installDir" : path .Join (Config .RuntimesDirectory (), nodeFileName ),
41- "node" : path .Join (Config .RuntimesDirectory (), nodeFileName , "bin" , "node" ),
42- "npm" : path .Join (Config .RuntimesDirectory (), nodeFileName , "bin" , "npm" ),
41+ "installDir" : path .Join (Config .RuntimesDirectory (), nodeFileName ),
42+ "node" : path .Join (Config .RuntimesDirectory (), nodeFileName , "bin" , "node" ),
43+ "npm" : path .Join (Config .RuntimesDirectory (), nodeFileName , "bin" , "npm" ),
4344 }
4445}
4546
@@ -60,24 +61,30 @@ func getNodeDownloadURL(nodeRuntime *Runtime) string {
6061func InstallNode (r * Runtime ) error {
6162 // TODO should delete downloaded archive
6263 // TODO check for deflated archive
63- log .Println ("Fetching node..." )
6464 downloadNodeURL := getNodeDownloadURL (r )
65- nodeTar , err := utils .DownloadFile (downloadNodeURL , Config .RuntimesDirectory ())
66- if err != nil {
67- return err
68- }
69-
70- // deflate node archive
71- t , err := os .Open (nodeTar )
65+ fileName := filepath .Base (downloadNodeURL )
66+ t , err := os .Open (filepath .Join (Config .RuntimesDirectory (), fileName ))
7267 defer t .Close ()
7368 if err != nil {
74- return err
69+ log .Println ("Node is not present, fetching node..." )
70+ nodeTar , err := utils .DownloadFile (downloadNodeURL , Config .RuntimesDirectory ())
71+ if err != nil {
72+ return err
73+ }
74+ t , err = os .Open (nodeTar )
75+ defer t .Close ()
76+ if err != nil {
77+ return err
78+ }
79+ } else {
80+ fmt .Println ("Node is already present..." )
7581 }
82+ fmt .Println ("Extracting node..." )
83+ // deflate node archive
84+
7685 err = utils .ExtractTarGz (t , Config .RuntimesDirectory ())
7786 if err != nil {
7887 return err
7988 }
80-
8189 return nil
8290}
83-
0 commit comments