From bc10b397128270f8077559cc017aa953531b6fec Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 02:41:01 +0700
Subject: [PATCH 1/6] fix(installer): handle removal of deleted templates
 during update

Signed-off-by: Dwi Siswanto <git@dw1.io>
---
 pkg/installer/template.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index 37a959cf1e..bffd7fe4ad 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -151,6 +151,13 @@ func (t *TemplateManager) updateTemplatesAt(dir string) error {
 	// summarize all changes
 	results := t.summarizeChanges(oldchecksums, newchecksums)
 
+	// remove deleted templates
+	for _, deletion := range results.deletions {
+		if err := os.Remove(deletion); err != nil {
+			gologger.Warning().Msgf("failed to remove deleted template %s: %s", deletion, err)
+		}
+	}
+
 	// print summary
 	if results.totalCount > 0 {
 		gologger.Info().Msgf("Successfully updated nuclei-templates (%v) to %s. GoodLuck!", ghrd.Latest.GetTagName(), dir)

From 89f0d684a23e9d1afd1c6f7c5f3df6a80b5f2e6b Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 03:07:34 +0700
Subject: [PATCH 2/6] chore(installer): no log for non-existent deleted
 templates err

Signed-off-by: Dwi Siswanto <git@dw1.io>
---
 pkg/installer/template.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index bffd7fe4ad..300935048c 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -153,7 +153,7 @@ func (t *TemplateManager) updateTemplatesAt(dir string) error {
 
 	// remove deleted templates
 	for _, deletion := range results.deletions {
-		if err := os.Remove(deletion); err != nil {
+		if err := os.Remove(deletion); err != nil && !os.IsNotExist(err) {
 			gologger.Warning().Msgf("failed to remove deleted template %s: %s", deletion, err)
 		}
 	}

From 8175e2a291b7bbfdae8c8ab55ba54703c1958e99 Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 03:09:15 +0700
Subject: [PATCH 3/6] feat(installer): purge empty dirs after removing deleted
 templates

Signed-off-by: Dwi Siswanto <git@dw1.io>
---
 pkg/installer/template.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index 300935048c..d6a2a94e87 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -155,6 +155,8 @@ func (t *TemplateManager) updateTemplatesAt(dir string) error {
 	for _, deletion := range results.deletions {
 		if err := os.Remove(deletion); err != nil && !os.IsNotExist(err) {
 			gologger.Warning().Msgf("failed to remove deleted template %s: %s", deletion, err)
+		} else {
+			PurgeEmptyDirectories(filepath.Dir(deletion))
 		}
 	}
 

From a41174b40ef49dfadb242d52a41e03c280ce6e04 Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 03:41:08 +0700
Subject: [PATCH 4/6] Revert "feat(installer): purge empty dirs after removing
 deleted templates"

This reverts commit 8175e2a291b7bbfdae8c8ab55ba54703c1958e99.
---
 pkg/installer/template.go | 2 --
 1 file changed, 2 deletions(-)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index d6a2a94e87..300935048c 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -155,8 +155,6 @@ func (t *TemplateManager) updateTemplatesAt(dir string) error {
 	for _, deletion := range results.deletions {
 		if err := os.Remove(deletion); err != nil && !os.IsNotExist(err) {
 			gologger.Warning().Msgf("failed to remove deleted template %s: %s", deletion, err)
-		} else {
-			PurgeEmptyDirectories(filepath.Dir(deletion))
 		}
 	}
 

From 4ae00c2ce49df98ec6723c8ab872402b3352fc0d Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 14:32:26 +0700
Subject: [PATCH 5/6] fix(installer): use semicolons as delimiters

Signed-off-by: Dwi Siswanto <git@dw1.io>
---
 pkg/installer/template.go | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index 300935048c..f3a8972e57 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -350,7 +350,7 @@ func (t *TemplateManager) getChecksumFromDir(dir string) (map[string]string, err
 		checksums, err := os.ReadFile(checksumFilePath)
 		if err == nil {
 			allChecksums := make(map[string]string)
-			for _, v := range strings.Split(string(checksums), "\n") {
+			for _, v := range strings.Split(string(checksums), ";") {
 				v = strings.TrimSpace(v)
 				tmparr := strings.Split(v, ",")
 				if len(tmparr) != 2 {
@@ -373,7 +373,10 @@ func (t *TemplateManager) writeChecksumFileInDir(dir string) error {
 	}
 	var buff bytes.Buffer
 	for k, v := range checksumMap {
-		buff.WriteString(k + "," + v)
+		buff.WriteString(k)
+		buff.WriteString(",")
+		buff.WriteString(v)
+		buff.WriteString(";")
 	}
 	return os.WriteFile(config.DefaultConfig.GetChecksumFilePath(), buff.Bytes(), checkSumFilePerm)
 }

From 696c909611e18e0da8ea9d30527ba5ac7541dba6 Mon Sep 17 00:00:00 2001
From: Dwi Siswanto <git@dw1.io>
Date: Tue, 21 Jan 2025 14:33:20 +0700
Subject: [PATCH 6/6] feat(installer): add mods count in
 `*templateUpdateResults.String`

Signed-off-by: Dwi Siswanto <git@dw1.io>
---
 pkg/installer/template.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pkg/installer/template.go b/pkg/installer/template.go
index f3a8972e57..26d09f9f2f 100644
--- a/pkg/installer/template.go
+++ b/pkg/installer/template.go
@@ -45,10 +45,15 @@ type templateUpdateResults struct {
 func (t *templateUpdateResults) String() string {
 	var buff bytes.Buffer
 	data := [][]string{
-		{strconv.Itoa(t.totalCount), strconv.Itoa(len(t.additions)), strconv.Itoa(len(t.deletions))},
+		{
+			strconv.Itoa(t.totalCount),
+			strconv.Itoa(len(t.additions)),
+			strconv.Itoa(len(t.modifications)),
+			strconv.Itoa(len(t.deletions)),
+		},
 	}
 	table := tablewriter.NewWriter(&buff)
-	table.SetHeader([]string{"Total", "Added", "Removed"})
+	table.SetHeader([]string{"Total", "Added", "Modified", "Removed"})
 	for _, v := range data {
 		table.Append(v)
 	}