Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows database.Reset #215

Merged
merged 1 commit into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"database/sql"
"errors"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -38,10 +39,20 @@ func Initialize(databasePath string) {
DB = conn
}

func Reset(databasePath string) {
_ = DB.Close()
_ = os.Remove(databasePath)
func Reset(databasePath string) error {
err := DB.Close()

if err != nil {
return errors.New("Error closing database: " + err.Error())
}

err = os.Remove(databasePath)
if err != nil {
return errors.New("Error removing database: " + err.Error())
}

Initialize(databasePath)
return nil
}

// Migrate the database
Expand Down Expand Up @@ -71,6 +82,7 @@ func runMigrations(databasePath string) {
panic(err.Error())
}
}
m.Close()
}

func registerRegexpFunc() {
Expand Down
14 changes: 10 additions & 4 deletions pkg/manager/task_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package manager
import (
"context"
"database/sql"
"strconv"
"sync"
"time"

"github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/stashapp/stash/pkg/manager/jsonschema"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"strconv"
"sync"
"time"
)

type ImportTask struct {
Expand All @@ -34,7 +35,12 @@ func (t *ImportTask) Start(wg *sync.WaitGroup) {
}
t.Scraped = scraped

database.Reset(config.GetDatabasePath())
err := database.Reset(config.GetDatabasePath())

if err != nil {
logger.Errorf("Error resetting database: %s", err.Error())
return
}

ctx := context.TODO()

Expand Down