func (m *Manager) RescanExecute(j *jobs.Job) error {
	return m.singleRepoExecute(repo.Rescan, j)
}
RescanExecute carries out a Rescan job
package manager
import (
	"errors"
	"fmt"
	"github.com/getsolus/ferryd/config"
	"github.com/getsolus/ferryd/jobs"
	"github.com/getsolus/ferryd/repo"
	"github.com/getsolus/ferryd/util"
	"github.com/jmoiron/sqlx"
	"os"
	"path/filepath"
)
type singleRepoFunc func(r *repo.Repo, j *jobs.Job, tx *sqlx.Tx) error
func (m *Manager) singleRepoExecute(single singleRepoFunc, j *jobs.Job) error {
	if len(j.Src) == 0 {
		return errors.New("job is missing a source repo")
	}
	tx, err := m.db.Beginx()
	if err != nil {
		return fmt.Errorf("Failed to start DB transaction, reason: '%s'", err.Error())
	}
	r, err := repo.Get(tx, j.Src)
	if err != nil {
		tx.Rollback()
		return fmt.Errorf("Failed to get the Repo entry from the DB, reason: '%s'", err.Error())
	}
	if err = single(r, j, tx); err != nil {
		tx.Rollback()
		return err
	}
	if err = tx.Commit(); err != nil {
		return fmt.Errorf("Failed to remove the Repo from the DB, reason: '%s'", err.Error())
	}
	return nil
}
func (m *Manager) Check(name string) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	j := &jobs.Job{
		Type: jobs.Check,
		Src:  name,
	}
	return m.store.Push(j)
}
func (m *Manager) CheckExecute(j *jobs.Job) error {
	var d *repo.Diff
	if len(j.Src) == 0 {
		return errors.New("job is missing a source repo")
	}
	tx, err := m.db.Beginx()
	if err != nil {
		return err
	}
	r, err := repo.Get(tx, j.Src)
	if err != nil {
		goto ROLLBACK
	}
	d, err = r.Check(tx)
	if err != nil {
		goto ROLLBACK
	}
	tx.Commit()
	j.Results, err = d.MarshalBinary()
	return err
ROLLBACK:
	tx.Rollback()
	return err
}
func (m *Manager) Create(name string, instant bool) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a destination repo")
	}
	max := 0
	if instant {
		max = 1
	}
	j := &jobs.Job{
		Type: jobs.Create,
		Dst:  name,
		Max:  max,
	}
	return m.store.Push(j)
}
func (m *Manager) CreateExecute(j *jobs.Job) error {
	if len(j.Dst) == 0 {
		return errors.New("job is missing a destination repo")
	}
	if j.Dst == "pool" {
		return errors.New("'pool' is a reserved name and cannot be used for a new repo")
	}
	rp := filepath.Join(config.Current.RepoPath(), j.Dst)
	if err := util.CreateDir(rp); err != nil {
		return err
	}
	ap := filepath.Join(config.Current.AssetPath(), j.Dst)
	if err := util.CreateDir(ap); err != nil {
		return err
	}
	assetsDir := filepath.Join(config.Current.AssetPath(), j.Dst)
	poolAssets := filepath.Join(config.Current.AssetPath(), "pool")
	if err := util.CopyDir(poolAssets, assetsDir, false); err != nil {
		return fmt.Errorf("Failed to create assets dir, reason: '%s'", err.Error())
	}
	tx, err := m.db.Beginx()
	if err != nil {
		return fmt.Errorf("Failed to create transaction, reason: '%s'", err.Error())
	}
	r := &repo.Repo{
		Name:           j.Dst,
		InstantTransit: j.Max == 1,
	}
	if err = r.Create(tx); err != nil {
		tx.Rollback()
		return fmt.Errorf("Failed to create repo entry in DB, reason: '%s'", err.Error())
	}
	return tx.Commit()
}
func (m *Manager) Delta(name string) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	j := &jobs.Job{
		Type: jobs.Delta,
		Src:  name,
	}
	return m.store.Push(j)
}
func (m *Manager) DeltaExecute(j *jobs.Job) error {
	return m.singleRepoExecute(repo.Delta, j)
}
func (m *Manager) Import(name string, instant bool) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	max := 0
	if instant {
		max = 1
	}
	j := &jobs.Job{
		Type: jobs.Import,
		Src:  name,
		Max:  max,
	}
	return m.store.Push(j)
}
func (m *Manager) ImportExecute(j *jobs.Job) error {
	if len(j.Dst) == 0 {
		return errors.New("job is missing a destination repo")
	}
	repoDir := filepath.Join(config.Current.RepoPath(), j.Dst)
	if _, err := os.Stat(repoDir); err != nil {
		if os.IsNotExist(err) {
			return fmt.Errorf("repo directory for '%s' does not exist", j.Dst)
		}
		return err
	}
	tx, err := m.db.Beginx()
	if err != nil {
		return fmt.Errorf("Failed to create transaction, reason: '%s'", err.Error())
	}
	r := &repo.Repo{
		Name:           j.Dst,
		InstantTransit: j.Max == 1,
	}
	if err = r.Create(tx); err != nil {
		tx.Rollback()
		return fmt.Errorf("Failed to create repo entry in DB, reason: '%s'", err.Error())
	}
	if err = tx.Commit(); err != nil {
		return fmt.Errorf("Failed to create repo entry in DB, reason: '%s'", err.Error())
	}
	return m.RescanExecute(j)
}
func (m *Manager) Index(name string) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	j := &jobs.Job{
		Type: jobs.Index,
		Src:  name,
	}
	return m.store.Push(j)
}
func (m *Manager) IndexExecute(j *jobs.Job) error {
	return m.singleRepoExecute(repo.Index, j)
}
func (m *Manager) Remove(name string) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	j := &jobs.Job{
		Type: jobs.Remove,
		Src:  name,
	}
	return m.store.Push(j)
}
func (m *Manager) RemoveExecute(j *jobs.Job) error {
	return m.singleRepoExecute(repo.Remove, j)
}
func (m *Manager) Rescan(name string) (int, error) {
	if len(name) == 0 {
		return -1, errors.New("job is missing a source repo")
	}
	j := &jobs.Job{
		Type: jobs.Rescan,
		Src:  name,
	}
	return m.store.Push(j)
}