summaryrefslogtreecommitdiff
path: root/store/tag.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/tag.go')
-rw-r--r--store/tag.go34
1 files changed, 12 insertions, 22 deletions
diff --git a/store/tag.go b/store/tag.go
index 5f717bd..2c11880 100644
--- a/store/tag.go
+++ b/store/tag.go
@@ -2,6 +2,7 @@ package store
import (
"encoding/json"
+ "fmt"
log "github.com/sirupsen/logrus"
"os"
"time"
@@ -17,8 +18,7 @@ type Tag struct {
func (s *Store) Tags() []string {
var tags []string
if entries, err := os.ReadDir(s.TagsDir()); err != nil {
- log.Fatalf("Error while reading tags, %s", err)
- os.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error reading tags, %s", err))
} else {
for _, entry := range entries {
if entry.IsDir() {
@@ -36,8 +36,7 @@ func (s *Store) Tag(tag string) []string {
}
var images []string
if entries, err := os.ReadDir(s.TagPath(tag)); err != nil {
- log.Fatalf("Error while reading tag %s, %s", tag, err)
- os.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error reading tag %s, %s", tag, err))
} else {
for _, entry := range entries {
if entry.Name() == infoJson {
@@ -58,16 +57,13 @@ func (s *Store) TagCreate(tag string) bool {
return false
}
if err := os.Mkdir(s.TagPath(tag), s.PermissionDir); err != nil {
- log.Fatalf("Error while creating tag %s, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error creating tag %s, %s", tag, err))
}
if payload, err := json.Marshal(Tag{Type: Generic, CreationTime: time.Now().UTC()}); err != nil {
- log.Fatalf("Error while generating tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error generating tag %s metadata, %s", tag, err))
} else {
if err = os.WriteFile(s.TagMetadataPath(tag), payload, s.PermissionFile); err != nil {
- log.Fatalf("Error while writing tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error writing tag %s metadata, %s", tag, err))
}
}
log.Infof("Tag %s created.", tag)
@@ -87,12 +83,10 @@ func (s *Store) TagDestroy(tag string) {
s.ImageTagRemove(flake, tag)
}
if err := os.Remove(s.TagMetadataPath(tag)); err != nil {
- log.Fatalf("Error removing tag %s metadata, %s", tag, err)
- os.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error removing tag %s metadata, %s", tag, err))
}
if err := os.Remove(s.TagPath(tag)); err != nil {
- log.Fatalf("Error removing tag %s, %s", tag, err)
- os.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error removing tag %s, %s", tag, err))
}
log.Infof("Tag %s destroyed.", tag)
}
@@ -106,13 +100,11 @@ func (s *Store) TagInfo(tag string) Tag {
s.getLock("tag_" + tag).RLock()
defer s.getLock("tag_" + tag).RUnlock()
if payload, err := os.ReadFile(s.TagMetadataPath(tag)); err != nil {
- log.Fatalf("Error while reading tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error reading tag %s metadata, %s", tag, err))
} else {
var info Tag
if err = json.Unmarshal(payload, &info); err != nil {
- log.Fatalf("Error while parsing tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error parsing tag %s metadata, %s", tag, err))
} else {
return info
}
@@ -141,12 +133,10 @@ func (s *Store) TagType(tag, t string) {
info := s.TagInfo(tag)
info.Type = t
if payload, err := json.Marshal(info); err != nil {
- log.Fatalf("Error while updating tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error updating tag %s metadata, %s", tag, err))
} else {
if err = os.WriteFile(s.TagMetadataPath(tag), payload, s.PermissionFile); err != nil {
- log.Fatalf("Error while writing tag %s metadata, %s", tag, err)
- log.Exit(1)
+ s.fatalClose(fmt.Sprintf("Error writing tag %s metadata, %s", tag, err))
}
}
log.Infof("Tag %s type set to %s.", tag, t)