aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-01-02 22:25:11 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2022-01-02 22:25:11 -0500
commitcbfd82db8a20be32ffa82a1afa860729f3097de6 (patch)
treed671f714b32bfb64a56f88a02ae6f40041e6e033
parented9a9bb126984cdb38a510281a2cb26281e035b1 (diff)
downloadsteam-export-dev.tar.gz
steam-export-dev.tar.xz
Fix bug in JSON output for errors. Fix extract bug due to unset library path.dev
-rw-r--r--cmd/web/apiv1.go2
-rw-r--r--cmd/web/handlers.go2
-rw-r--r--steam/extract.go13
-rw-r--r--steam/status.go10
4 files changed, 21 insertions, 6 deletions
diff --git a/cmd/web/apiv1.go b/cmd/web/apiv1.go
index 29d93cb..1bc9b7b 100644
--- a/cmd/web/apiv1.go
+++ b/cmd/web/apiv1.go
@@ -167,7 +167,7 @@ func (a *App) HandleInstallV1(w http.ResponseWriter, r *http.Request) {
if err != nil {
Logger.Printf("Error encountered installing: %s", err)
}
- Logger.Printf("Extrated game: %s", g)
+ Logger.Printf("Extracted game: %s", g)
}()
time.Sleep(time.Millisecond * 50)
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index 06d699c..182b100 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -52,7 +52,7 @@ func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) {
if err != nil {
Logger.Printf("Error encountered installing: %s", err)
}
- Logger.Printf("Extrated game: %s", g)
+ Logger.Printf("Extracted game: %s", g)
}()
http.Redirect(w, r, "/", 302)
diff --git a/steam/extract.go b/steam/extract.go
index d93428d..45a760b 100644
--- a/steam/extract.go
+++ b/steam/extract.go
@@ -154,6 +154,7 @@ func (l *Library) extractPrimitive(j *Job, g *Game, r io.Reader) (*Game, error)
break
}
if err != nil {
+ err = fmt.Errorf("tar reader: %w", err)
j.addError(err)
return nil, err
}
@@ -171,10 +172,9 @@ func (l *Library) extractPrimitive(j *Job, g *Game, r io.Reader) (*Game, error)
info := hdr.FileInfo()
if info.IsDir() {
- // I don't like hard-coded permissions but it
- // it helps with overall platform compatibility
err = os.MkdirAll(fileName, defaultDirectoryMode)
if err != nil {
+ err = fmt.Errorf("os.MkDirAll for directory: %w", err)
j.addError(err)
return nil, err
}
@@ -184,6 +184,7 @@ func (l *Library) extractPrimitive(j *Job, g *Game, r io.Reader) (*Game, error)
err = os.MkdirAll(filepath.Dir(fileName), defaultDirectoryMode)
if err != nil {
+ err = fmt.Errorf("os.MkDirAll for file: %w", err)
j.addError(err)
return nil, err
}
@@ -193,10 +194,13 @@ func (l *Library) extractPrimitive(j *Job, g *Game, r io.Reader) (*Game, error)
defaultFileMode)
if err != nil {
+ err = fmt.Errorf(
+ "while opening file handle for tarball extraction: %w", err)
j.addError(err)
return nil, err
}
if _, err := io.Copy(f, treader); err != nil {
+ err = fmt.Errorf("while copying from treader: %w", err)
j.addError(err)
f.Close()
return nil, err
@@ -205,8 +209,13 @@ func (l *Library) extractPrimitive(j *Job, g *Game, r io.Reader) (*Game, error)
}
+ if g.LibraryPath == "" {
+ g.LibraryPath = l.folder
+ }
+
err := g.SetSizeInfo()
if err != nil {
+ err = fmt.Errorf("while setting size info: %w", err)
j.addError(err)
return nil, err
}
diff --git a/steam/status.go b/steam/status.go
index ffb1ac3..6b0d874 100644
--- a/steam/status.go
+++ b/steam/status.go
@@ -44,7 +44,7 @@ type JobStatusJson struct {
Target *Game `json:"Target" example:"Doom"` // Name of the target game
Running bool `json:"Running" example:"false"` // Whether or not the job is running
Start *time.Time `json:"Start" example:"1629855616"` // Start time as a unix timestamp
- Errors []error `json:"Errors"` // List of all errors encountered through the course of the job
+ Errors []string `json:"Errors"` // List of all errors encountered through the course of the job
// If applicablle
Size *int64 `json:"Size" example:"12345"` // Game size in bytes
@@ -53,13 +53,19 @@ type JobStatusJson struct {
}
func (j Job) MarshalJSON() ([]byte, error) {
+
+ errs := []string{}
+ for _, e := range j.errors {
+ errs = append(errs, e.Error())
+ }
+
return json.Marshal(
&JobStatusJson{
Action: j.action,
Target: j.target,
Running: j.running,
Start: j.start,
- Errors: j.errors,
+ Errors: errs,
Size: j.size,
Transferred: j.transferred,
Eta: j.eta,