Skip to content

Commit

Permalink
clean up usage of path
Browse files Browse the repository at this point in the history
  • Loading branch information
sselph committed May 29, 2017
1 parent f284bb8 commit 1879a82
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
13 changes: 6 additions & 7 deletions ds/ovgdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -134,7 +133,7 @@ func updateDB(ctx context.Context, version, p string) error {
log.Printf("WARN: Using cached OpenVGDB. Server over quota.")
return nil
}
dbp := path.Join(p, dbName)
dbp := filepath.Join(p, dbName)
err = os.RemoveAll(dbp)
if err != nil {
return err
Expand All @@ -149,7 +148,7 @@ func updateDB(ctx context.Context, version, p string) error {
if err != nil {
return err
}
zf := path.Join(p, zipName)
zf := filepath.Join(p, zipName)
err = ioutil.WriteFile(zf, b, 0664)
if err != nil {
return err
Expand All @@ -170,14 +169,14 @@ func updateDB(ctx context.Context, version, p string) error {
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(dbp, n), b, 0664)
err = ioutil.WriteFile(filepath.Join(dbp, n), b, 0664)
if err != nil {
return err
}
}
log.Print("INFO: Upgrade Complete.")
os.Remove(zf)
ioutil.WriteFile(path.Join(p, metaName), []byte(newVersion), 0664)
ioutil.WriteFile(filepath.Join(p, metaName), []byte(newVersion), 0664)
return nil
}

Expand All @@ -194,8 +193,8 @@ func getDB(ctx context.Context, p string, u bool) (*leveldb.DB, error) {
if err != nil {
return nil, err
}
fp := path.Join(p, dbName)
mp := path.Join(p, metaName)
fp := filepath.Join(p, dbName)
mp := filepath.Join(p, metaName)
if exists(fp) && exists(mp) {
b, err := ioutil.ReadFile(mp)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions ovgdb-dl/ovgdb-dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -180,7 +180,7 @@ func updateDB(version, p string) error {
if err != nil {
return err
}
zf := path.Join(p, zipName)
zf := filepath.Join(p, zipName)
err = ioutil.WriteFile(zf, b, 0664)
if err != nil {
return err
Expand All @@ -203,10 +203,10 @@ func updateDB(version, p string) error {
if err != nil {
return err
}
ioutil.WriteFile(path.Join(p, metaName), []byte(r.TagName), 0664)
ioutil.WriteFile(filepath.Join(p, metaName), []byte(r.TagName), 0664)
os.Remove(zf)
log.Print("INFO: Upgrade Complete.")
return ioutil.WriteFile(path.Join(p, fileName), b, 0664)
return ioutil.WriteFile(filepath.Join(p, fileName), b, 0664)
}
}
return fmt.Errorf("no openvgdb found")
Expand Down
4 changes: 2 additions & 2 deletions rom/hash/7zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"

"github.com/kjk/lzmadec"
Expand All @@ -27,7 +27,7 @@ func decode7Zip(f string) (io.ReadCloser, error) {
return nil, err
}
for _, e := range r.Entries {
ext := path.Ext(e.Path)
ext := filepath.Ext(e.Path)
if decoder, ok := getDecoder(ext); ok {
rf, err := r.GetFileReader(e.Path)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions rom/hash/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
)

func decodeGZip(f string) (io.ReadCloser, error) {
Expand All @@ -21,7 +21,7 @@ func decodeGZip(f string) (io.ReadCloser, error) {
return nil, err
}
defer gzr.Close()
ext := path.Ext(gzr.Header.Name)
ext := filepath.Ext(gzr.Header.Name)
if decoder, ok := getDecoder(ext); ok {
d, err := ioutil.ReadAll(gzr)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions rom/hash/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"archive/zip"
"fmt"
"io"
"path"
"path/filepath"
)

type zipReader struct {
Expand All @@ -29,7 +29,7 @@ func decodeZip(f string) (io.ReadCloser, error) {
}
var zr zipReader
for _, zf := range r.File {
ext := path.Ext(zf.FileHeader.Name)
ext := filepath.Ext(zf.FileHeader.Name)
if decoder, ok := getDecoder(ext); ok {
rf, err := zf.Open()
if err != nil {
Expand Down
16 changes: 4 additions & 12 deletions rom/rom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -385,9 +384,9 @@ func fileExists(p string, ext ...string) (string, bool) {
return p, false
}

// Not sure if this is the right place for this.
// convertVideo transcodes a video using HandBrakeCLI.
func convertVideo(p string) error {
vidExt := path.Ext(p)
vidExt := filepath.Ext(p)
baseFile := p[:len(p)-len(vidExt)]
outputFile := baseFile + "-converting" + vidExt
// Hardcoded command for now, clean this up once we offer more
Expand All @@ -402,17 +401,10 @@ func convertVideo(p string) error {
"--audio", "1",
"-B", "80",
"-E", "av_aac")
err := cmd.Run()
if err != nil {
if err := cmd.Run(); err != nil {
return err
}

err = os.Rename(outputFile, p)
if err != nil {
return err
}

return nil
return os.Rename(outputFile, p)
}

// XML creates the XML for the ROM after the Game has been populates.
Expand Down

0 comments on commit 1879a82

Please sign in to comment.