From cb343c45060c51ec37b01ef7df05e9beac433763 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sun, 15 Jul 2018 19:00:08 +0000 Subject: [PATCH] Move copy templates out --- appvm.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/appvm.go b/appvm.go index 66689ca..9941148 100644 --- a/appvm.go +++ b/appvm.go @@ -149,6 +149,23 @@ func copyFile(from, to string) (err error) { return destination.Close() } +func prepareTemplates(appvmPath string) (err error) { + if _, err = os.Stat(appvmPath + "/nix/local.nix"); os.IsNotExist(err) { + err = copyFile(appvmPath+"/nix/local.nix.template", appvmPath+"/nix/local.nix") + if err != nil { + return + } + } + + if _, err = os.Stat(appvmPath + "/nix/monitor.nix"); os.IsNotExist(err) { + err = copyFile(appvmPath+"/nix/monitor.nix.template", appvmPath+"/nix/monitor.nix") + if err != nil { + return + } + } + return +} + func start(l *libvirt.Libvirt, name string) { // Currently binary-only installation is not supported, because we need *.nix configurations gopath := os.Getenv("GOPATH") @@ -159,18 +176,9 @@ func start(l *libvirt.Libvirt, name string) { } // Copy templates - if _, err := os.Stat(appvmPath + "/nix/local.nix"); os.IsNotExist(err) { - err = copyFile(appvmPath+"/nix/local.nix.template", appvmPath+"/nix/local.nix") - if err != nil { - log.Fatal(err) - } - } - - if _, err := os.Stat(appvmPath + "/nix/monitor.nix"); os.IsNotExist(err) { - err = copyFile(appvmPath+"/nix/monitor.nix.template", appvmPath+"/nix/monitor.nix") - if err != nil { - log.Fatal(err) - } + err := prepareTemplates(name) + if err != nil { + log.Fatal(err) } stdout, stderr, ret, err := system.System("nix-build", "", "-A", "config.system.build.vm",