From 4ed0f4a78d4c3efdbd35efee796983856fde7a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Pani=C4=87?= Date: Sat, 17 Jul 2021 23:07:21 +0200 Subject: [PATCH] Remove control patchfile after revert --- generator/generator.go | 1 + generator/patch.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/generator/generator.go b/generator/generator.go index 5cacc6a..c70d032 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -64,6 +64,7 @@ func Close() { } if fdRevert != nil { + fdRevert.WriteString(fmt.Sprintf("rm -rf %s\n", patchFilesControlFile)) fdRevert.Sync() fdRevert.Close() } diff --git a/generator/patch.go b/generator/patch.go index 24bfdbb..2add387 100644 --- a/generator/patch.go +++ b/generator/patch.go @@ -60,18 +60,21 @@ func writePatch(p *parser.Result, environment string, log *zap.Logger) (err erro bodyCommented = strings.Trim(bodyCommented, "\n") // generate payload - p.Patch.Body = fmt.Sprintf("\n%s PATCHFILES START\n%s\n%s PATCHFILES END\n", p.Patch.CommentCharacter, p.Patch.Body, p.Patch.CommentCharacter) - payload := base64.StdEncoding.EncodeToString([]byte(p.Patch.Body)) + if p.Patch.Mode == "append" { + p.Patch.Body = fmt.Sprintf("\n%s PATCHFILES START\n%s\n%s PATCHFILES END\n", p.Patch.CommentCharacter, p.Patch.Body, p.Patch.CommentCharacter) + } + payload := base64.StdEncoding.EncodeToString([]byte(p.Patch.Body + "\n")) // write mode + commandsAfter := p.Patch.CommandsAfter writeMode := ">" if p.Patch.Mode == "append" { writeMode = ">>" + } else { + command := fmt.Sprintf("cp -r %s %s.oldpatchfile", p.Patch.Output, p.Patch.Output) + commandsAfter = append(commandsAfter, command) } - commandsAfter := p.Patch.CommandsAfter - command := fmt.Sprintf("cp -r %s %s.oldpatchfile", p.Patch.Output, p.Patch.Output) - commandsAfter = append(commandsAfter, command) var ( buf = new(bytes.Buffer) )