diff --git a/config.go b/config.go index 58867fa8c42186295266b8f01bdb7ff610379cc6..b064e143718d5d7734d267bafe7ff39bd1553c51 100644 --- a/config.go +++ b/config.go @@ -4,11 +4,13 @@ import ( "github.com/fsnotify/fsnotify" log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "random.chars.jp/git/image-board/store" "strconv" ) -var instance *store.Store +var ( + serverConfig map[string]interface{} + systemConfig map[string]interface{} +) func configSetup() { // Configure configuration file parameters @@ -78,34 +80,6 @@ func configSetup() { systemConfig = viper.GetStringMap("system") } -func openStore() { - path := systemConfig["store"].(string) - single := parseBool(systemConfig["single-user"]) - private := parseBool(systemConfig["private"]) - - instance = store.New(path, single, private) - if instance == nil { - log.Fatalf("Error initializing store.") - } - log.Infof("Store opened on %s revision %v compat %v.", path, instance.Revision, instance.Compat) - info := instance.User(instance.InitialUser) - if info.Snowflake == instance.InitialUser { - log.Infof("Initial user ID %s secret %s.", info.Snowflake, info.Secret) - if instance.UserPasswordValidate(info.Snowflake, "initial") { - log.Warnf("Initial user still has the initial password.") - } - } else { - if single { - log.Fatal("Instance has no initial user, single user mode unavailable.") - } - } - if single { - log.Info("Server running in single user mode, all operations are performed as the initial user.") - } else if private { - log.Info("Server running in private mode, all operations will require authentication.") - } -} - func parseBool(v interface{}) bool { if s, ok := v.(bool); !ok { var sS string diff --git a/main.go b/main.go index acf82b6de6c8fb6493d4eac15425ac5e3ebe6213..febca53400d862903d550783822342e4ed5a52f7 100644 --- a/main.go +++ b/main.go @@ -5,15 +5,12 @@ import ( "net/http" "os" "os/signal" + "random.chars.jp/git/image-board/store" "syscall" ) var ( - serverConfig map[string]interface{} - systemConfig map[string]interface{} -) - -var ( + instance *store.Store server = http.Server{} executable string ) @@ -81,3 +78,31 @@ func main() { restart() } } + +func openStore() { + path := systemConfig["store"].(string) + single := parseBool(systemConfig["single-user"]) + private := parseBool(systemConfig["private"]) + + instance = store.New(path, single, private) + if instance == nil { + log.Fatalf("Error initializing store.") + } + log.Infof("Store opened on %s revision %v compat %v.", path, instance.Revision, instance.Compat) + info := instance.User(instance.InitialUser) + if info.Snowflake == instance.InitialUser { + log.Infof("Initial user ID %s secret %s.", info.Snowflake, info.Secret) + if instance.UserPasswordValidate(info.Snowflake, "initial") { + log.Warnf("Initial user still has the initial password.") + } + } else { + if single { + log.Fatal("Instance has no initial user, single user mode unavailable.") + } + } + if single { + log.Info("Server running in single user mode, all operations are performed as the initial user.") + } else if private { + log.Info("Server running in private mode, all operations will require authentication.") + } +} diff --git a/store/image.go b/store/image.go index 9df4293bdb213cf86050b1b96ff247be07b549f4..4bd360fb52822d32044cf238304502bf6ce4a04b 100644 --- a/store/image.go +++ b/store/image.go @@ -428,11 +428,21 @@ func (s *Store) ImageDestroy(hash string) { return } + // Attempt to disassociate parent + s.ImageUpdate(hash, "\000", "", "\000", "\000") + s.getLock(hash).Lock() defer s.getLock(hash).Unlock() info := s.ImageMetadataRead(s.ImageMetadataPath(hash)) + // Disassociate child if set + if info.Child != "" { + if child := s.ImageSnowflake(info.Child); child.Snowflake == info.Child { + s.ImageUpdate(child.Hash, "\000", "", "\000", "\000") + } + } + // Untag the image completely tags := s.imageTags(info.Snowflake) for _, tag := range tags {