From 4de494505f95b7313a8d5b34ecac286db66698f9 Mon Sep 17 00:00:00 2001 From: Arnaud Lemaire Date: Fri, 31 Jul 2015 17:35:43 +0200 Subject: [PATCH] do not run build.sh if no build runlevel --- builder/cnt.go | 3 +++ utils/files.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 utils/files.go diff --git a/builder/cnt.go b/builder/cnt.go index e8fd3b1b..ab888aa8 100644 --- a/builder/cnt.go +++ b/builder/cnt.go @@ -204,6 +204,9 @@ func (cnt *Cnt) Build() error { } func (cnt *Cnt) runBuild() { + if res, err := utils.IsDirEmpty(cnt.target + "/runlevels/build"); res || err != nil { + return + } if err := utils.ExecCmd("systemd-nspawn", "--version"); err == nil { log.Get().Info("Run with systemd-nspawn") if err := utils.ExecCmd("systemd-nspawn", "--directory=" + cnt.rootfs, "--capability=all", diff --git a/utils/files.go b/utils/files.go new file mode 100644 index 00000000..5b59f84d --- /dev/null +++ b/utils/files.go @@ -0,0 +1,19 @@ +package utils +import ( + "os" + "io" +) + +func IsDirEmpty(name string) (bool, error) { + f, err := os.Open(name) + if err != nil { + return false, err + } + defer f.Close() + + _, err = f.Readdir(1) + if err == io.EOF { + return true, nil + } + return false, err // Either not empty or error, suits both cases +} \ No newline at end of file