~chrisppy/beagles

ed7d1dacd5c1a27799b28a9ce9461054e5f71ed7 — Chris Palmer 24 days ago bbb70ed
Fix db dir and add log file
4 files changed, 49 insertions(+), 21 deletions(-)

M CHANGELOG.md
M doc/beagles.1.scd
M main.go
M ui/ui.go
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 4,6 4,8 @@
### Breaking Changes
  - Database schema has been changed this will require deleting the database and
    starting anew (~chrisppy)
  - Database now defaults to XDG_DATA_HOME, since XDG_CACHE_HOME should be for
    tmp files (~chrisppy)
  - Config file has changed its structure, either adapt it based on man pages or
    delete and let beagles regenerate it (~chrisppy)


M doc/beagles.1.scd => doc/beagles.1.scd +4 -4
@@ 97,11 97,11 @@ beagles - TUI RSS feed aggregator

# ENVIRONMENT

	The config, database, download directories default to
	$HOME/.config/beagles, $HOME/.cache/beagles, and
	The config, database, download, and log directories default to
	$HOME/.config/beagles, $HOME/.local/share/beagles, and
	$HOME/.local/share/beagles , respectfully.  If you want to override
	these paths you must set the BEAGLES_CFG, BEAGLES_DB, and BEAGLES_DL
	environment variables within your shell.
	these paths you must set the BEAGLES_CFG, BEAGLES_DB, BEAGLES_DL,
	and BEAGLES_LOG environment variables within your shell.

# CONFIGURATION


M main.go => main.go +41 -17
@@ 36,9 36,32 @@ var (
)

func main() {
	wlog.SetFlags(log.Ltime)
	wlog.SetLevel(level.Info)
	wlog.SetFormat(format.Un)
	logger := wlog.New(os.Stdout, "", log.Ltime)
	logger.SetLevel(level.Info)
	logger.SetFormat(format.Un)

	logDir := os.Getenv("BEAGLES_LOG")
	if logDir == "" {
		d, err := os.UserCacheDir()
		if err != nil {
			wlog.Fatal(err.Error())
		}

		logDir = filepath.Join(d, "beagles")

		if _, err = os.Stat(logDir); os.IsNotExist(err) {
			if errDir := os.MkdirAll(logDir, 0750); errDir != nil {
				wlog.Fatal(err)
			}
		}
	}

	logPath := filepath.Clean(filepath.Join(logDir, "beagles.log"))
	f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 00600)
	if err != nil {
		wlog.Fatal(err.Error())
	}
	logger.SetOutput(f)

	configDir := os.Getenv("BEAGLES_CFG")
	if configDir == "" {


@@ 56,39 79,39 @@ func main() {
		}
	}

	cacheDir := os.Getenv("BEAGLES_DB")
	if cacheDir == "" {
		d, err := os.UserCacheDir()
	dbDir := os.Getenv("BEAGLES_DB")
	if dbDir == "" {
		d, err := os.UserHomeDir()
		if err != nil {
			wlog.Fatal(err.Error())
		}

		cacheDir = filepath.Join(d, "beagles")
		dbDir = filepath.Join(d, ".local", "share", "beagles")

		if _, err = os.Stat(cacheDir); os.IsNotExist(err) {
			if errDir := os.MkdirAll(cacheDir, 0750); errDir != nil {
		if _, err = os.Stat(dbDir); os.IsNotExist(err) {
			if errDir := os.MkdirAll(dbDir, 0750); errDir != nil {
				wlog.Fatal(err)
			}
		}
	}

	shareDir := os.Getenv("BEAGLES_DL")
	if shareDir == "" {
	dlDir := os.Getenv("BEAGLES_DL")
	if dlDir == "" {
		d, err := os.UserHomeDir()
		if err != nil {
			wlog.Fatal(err.Error())
		}
		shareDir = filepath.Join(d, ".local", "share", "beagles")

		if _, err = os.Stat(shareDir); os.IsNotExist(err) {
			if errDir := os.MkdirAll(shareDir, 0750); errDir != nil {
		dlDir = filepath.Join(d, ".local", "share", "beagles")

		if _, err = os.Stat(dlDir); os.IsNotExist(err) {
			if errDir := os.MkdirAll(dlDir, 0750); errDir != nil {
				wlog.Fatal(err)
			}
		}
	}

	path := filepath.Clean(filepath.Join(cacheDir, "beagles.db"))
	db, err := db.ReadDB(path)
	db, err := db.ReadDB(filepath.Clean(filepath.Join(dbDir, "beagles.db")))
	if err != nil {
		wlog.Fatal(err.Error())
	}


@@ 99,7 122,8 @@ func main() {
		Version:      Version,
		DB:           db,
		Config:       cfg,
		DownloadPath: shareDir,
		DownloadPath: dlDir,
		Logger:       logger,
	}

	i.Init()

M ui/ui.go => ui/ui.go +2 -0
@@ 23,6 23,7 @@ import (
	"git.sr.ht/~chrisppy/beagles/config"
	"git.sr.ht/~chrisppy/beagles/db"
	"git.sr.ht/~chrisppy/beagles/util"
	wlog "github.com/DataDrake/waterlog"
	"github.com/gdamore/tcell/v2"
	"gitlab.com/tslocum/cbind"
	tui "gitlab.com/tslocum/cview"


@@ 35,6 36,7 @@ type UI struct {
	DB           *db.Storage
	Config       *config.Config
	DownloadPath string
	Logger       *wlog.WaterLog
	inCmdMode    bool
	hideRead     bool
	status       statusType