// Copyright 2020 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package db import ( "fmt" "strings" "time" "github.com/jinzhu/gorm" "gogs.io/gogs/internal/errutil" ) // ReposStore is the persistent interface for repositories. // // NOTE: All methods are sorted in alphabetical order. type ReposStore interface { // GetByName returns the repository with given owner and name. // It returns ErrRepoNotExist when not found. GetByName(ownerID int64, name string) (*Repository, error) } var Repos ReposStore // NOTE: This is a GORM create hook. func (r *Repository) BeforeCreate() { r.CreatedUnix = gorm.NowFunc().Unix() } // NOTE: This is a GORM update hook. func (r *Repository) BeforeUpdate() { r.UpdatedUnix = gorm.NowFunc().Unix() } // NOTE: This is a GORM query hook. func (r *Repository) AfterFind() { r.Created = time.Unix(r.CreatedUnix, 0).Local() r.Updated = time.Unix(r.UpdatedUnix, 0).Local() } var _ ReposStore = (*repos)(nil) type repos struct { *gorm.DB } type ErrRepoAlreadyExist struct { args errutil.Args } func IsErrRepoAlreadyExist(err error) bool { _, ok := err.(ErrRepoAlreadyExist) return ok } func (err ErrRepoAlreadyExist) Error() string { return fmt.Sprintf("repository already exists: %v", err.args) } type createRepoOpts struct { Name string Description string DefaultBranch string Private bool Mirror bool EnableWiki bool EnableIssues bool EnablePulls bool Fork bool ForkID int64 } // create creates a new repository record in the database. Fields of "repo" will be updated // in place upon insertion. It returns ErrNameNotAllowed when the repository name is not allowed, // or ErrRepoAlreadyExist when a repository with same name already exists for the owner. func (db *repos) create(ownerID int64, opts createRepoOpts) (*Repository, error) { err := isRepoNameAllowed(opts.Name) if err != nil { return nil, err } _, err = db.GetByName(ownerID, opts.Name) if err == nil { return nil, ErrRepoAlreadyExist{args: errutil.Args{"ownerID": ownerID, "name": opts.Name}} } else if !IsErrRepoNotExist(err) { return nil, err } repo := &Repository{ OwnerID: ownerID, LowerName: strings.ToLower(opts.Name), Name: opts.Name, Description: opts.Description, DefaultBranch: opts.DefaultBranch, IsPrivate: opts.Private, IsMirror: opts.Mirror, EnableWiki: opts.EnableWiki, EnableIssues: opts.EnableIssues, EnablePulls: opts.EnablePulls, IsFork: opts.Fork, ForkID: opts.ForkID, } return repo, db.DB.Create(repo).Error } var _ errutil.NotFound = (*ErrRepoNotExist)(nil) type ErrRepoNotExist struct { args map[string]interface{} } func IsErrRepoNotExist(err error) bool { _, ok := err.(ErrRepoNotExist) return ok } func (err ErrRepoNotExist) Error() string { return fmt.Sprintf("repository does not exist: %v", err.args) } func (ErrRepoNotExist) NotFound() bool { return true } func (db *repos) GetByName(ownerID int64, name string) (*Repository, error) { repo := new(Repository) err := db.Where("owner_id = ? AND lower_name = ?", ownerID, strings.ToLower(name)).First(repo).Error if err != nil { if gorm.IsRecordNotFoundError(err) { return nil, ErrRepoNotExist{args: map[string]interface{}{"ownerID": ownerID, "name": name}} } return nil, err } return repo, nil } PANIC: session(release): write data/sessions/2/6/26388c22d8aaaa6b: no space left on device

PANIC

session(release): write data/sessions/2/6/26388c22d8aaaa6b: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)