diff --git a/main.go b/main.go index 37ffac66..2344fec7 100644 --- a/main.go +++ b/main.go @@ -168,6 +168,8 @@ func main() { err = os.MkdirAll(filepath.Join(outDir, outSandpointsDir, "_preview"), 0755) check(err) + published := isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit) + defer func() { lastPreviewCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "_preview", "last-commit-log.txt")) check(err) @@ -175,8 +177,9 @@ func main() { fmt.Fprintln(lastPreviewCommitLog, logLines) log.Printf(logLines) }() + defer func() { - if isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit) { + if published { lastGiteaCommitLog, err := os.Create(filepath.Join(outDir, outSandpointsDir, "last-commit-log.txt")) check(err) defer lastGiteaCommitLog.Close() @@ -184,7 +187,7 @@ func main() { } }() - if isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit) { + if published { hugoGiteaLogs := cage.Start() respGitea := commands.Execute([]string{"-s", tmpRepoPath, "-d", tmpHugoGiteaPath, "-e", "gitea"}) cage.Stop(hugoGiteaLogs) @@ -209,23 +212,33 @@ func main() { logLines = hugoLogs(logLines, hugoPreviewLogs.Data, "for _preview instance") - if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir)); err == nil { - err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir)) + if published { + if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir)); err == nil { + err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir)) + check(err) + } + } else if _, err := os.Stat(filepath.Join(outDir, outSandpointsDir, "_preview")); err == nil { + err := os.RemoveAll(filepath.Join(outDir, outSandpointsDir, "_preview")) check(err) } err = os.MkdirAll(outDir, 0755) check(err) - err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir)) - check(err) + if published { + err = os.Rename(tmpHugoGiteaPath, filepath.Join(outDir, outSandpointsDir)) + check(err) + } else { + err = os.Rename(tmpHugoPreviewPath, filepath.Join(outDir, outSandpointsDir, "_preview")) + check(err) + } - published := "" - if isPublished(gitRepoPath, gitIndexPath, prevCommit, lastCommit) { - published = " + published instance" + publishedMessage := "" + if published { + publishedMessage = " + published instance" } durationMillseconds := int64(time.Since(startTime) / time.Millisecond) - logLines = logLines + fmt.Sprintf("Total processing time (_preview%s): %d ms", published, durationMillseconds) + logLines = logLines + fmt.Sprintf("Total processing time (_preview%s): %d ms", publishedMessage, durationMillseconds) logGiteaLines = logGiteaLines + fmt.Sprintf("Total processing time (published + _preview instance): %d ms", durationMillseconds) } diff --git a/sphook b/sphook index 5c8926f2..8cfc24b9 100755 Binary files a/sphook and b/sphook differ