Skip to content

Commit 9d4aec9

Browse files
committed
use filepath.Join to append db filename.
1 parent 4ee513a commit 9d4aec9

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

cl/cl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cl
33
import (
44
"fmt"
55
"os/exec"
6+
"path/filepath"
67
"runtime"
78
"strconv"
89

@@ -30,7 +31,7 @@ func extractIndex(c *cli.Context) (int, error) {
3031
// and sets up the command line commands.
3132
func InitCli() *cli.App {
3233
dbpath := tv.DBPath()
33-
db, err := tv.RestoreProgrammeDB(dbpath + tv.NipDB)
34+
db, err := tv.RestoreProgrammeDB(filepath.Join(dbpath, tv.NipDB))
3435
if err != nil {
3536
panic(err)
3637
}

tv/db.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"io/ioutil"
77
"os"
8+
"path/filepath"
89
"strings"
910
"time"
1011

@@ -284,13 +285,12 @@ func RefreshDB(filename string) {
284285

285286
func init() {
286287
dbpath := DBPath()
287-
filename := NipDB
288-
pdb, err := RestoreProgrammeDB(dbpath + filename)
288+
pdb, err := RestoreProgrammeDB(filepath.Join(dbpath, NipDB))
289289
if err != nil {
290-
RefreshDB(dbpath + filename)
290+
RefreshDB(filepath.Join(dbpath, NipDB))
291291
} else {
292292
if pdb.sixHoursLater(time.Now()) || len(pdb.Categories) == 0 {
293-
RefreshDB(dbpath + filename)
293+
RefreshDB(filepath.Join(dbpath, NipDB))
294294
}
295295
}
296296
tobedel := pdb.toBeDeletedProgrammes()

tv/tv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ func DBPath() string {
341341
}
342342
path = filepath.Join(path, "nip")
343343
fmt.Println(path)
344-
if _, err := os.Stat(path + NipDB); os.IsNotExist(err) {
344+
if _, err := os.Stat(filepath.Join(path, NipDB)); os.IsNotExist(err) {
345345
err := os.MkdirAll(path, os.ModePerm)
346346
if err != nil {
347347
log.Fatal(err)
348348
}
349349
pdb := &ProgrammeDB{[]*Category{}, time.Now(), []*SavedProgramme{}}
350-
if err := pdb.Save(path + NipDB); err != nil {
350+
if err := pdb.Save(filepath.Join(path, NipDB)); err != nil {
351351
log.Fatal(err)
352352
}
353353
}

0 commit comments

Comments
 (0)