Skip to content

Commit

Permalink
fix(base/log): fix error that didn't check if PreviousPath exists bef…
Browse files Browse the repository at this point in the history
…ore loading it
  • Loading branch information
ramfox committed Apr 29, 2019
1 parent fe8f6d8 commit 748e58b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions api/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (h *LogHandlers) logHandler(w http.ResponseWriter, r *http.Request) {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}

util.WritePageResponse(w, res, r, params.Page())
if err := util.WritePageResponse(w, res, r, params.Page()); err != nil {
log.Infof("error list dataset history response: %s", err.Error())
}
}
6 changes: 4 additions & 2 deletions base/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ func DatasetLog(r repo.Repo, ref repo.DatasetRef, limit, offset int, loadDataset
rlog = append(rlog, ref)

limit--
if limit == 0 || ref.Dataset.PreviousPath == "" {
if limit == 0 {
break
}
}
if ref.Dataset.PreviousPath == "" {
break
}
ref.Path = ref.Dataset.PreviousPath
offset--
}

return rlog, nil
}

Expand Down
17 changes: 10 additions & 7 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ working backwards in time.`,
}

// cmd.Flags().StringVarP(&o.Format, "format", "f", "", "set output format [json]")
cmd.Flags().IntVarP(&o.Limit, "limit", "l", 25, "limit results, default 25")
cmd.Flags().IntVarP(&o.Offset, "offset", "o", 0, "offset results, default 0")
cmd.Flags().IntVar(&o.PageSize, "page-size", 25, "page size of results, default 25")
cmd.Flags().IntVar(&o.Page, "page", 1, "page number of results, default 1")

return cmd
}
Expand All @@ -47,9 +47,9 @@ working backwards in time.`,
type LogOptions struct {
ioes.IOStreams

Limit int
Offset int
Ref string
PageSize int
Page int
Ref string

LogRequests *lib.LogRequests
}
Expand Down Expand Up @@ -79,12 +79,15 @@ func (o *LogOptions) Run() error {
return err
}

// convert Page and PageSize to Limit and Offset
listParams := lib.NewListParams("", o.Page, o.PageSize)

p := &lib.LogParams{
Ref: ref,
ListParams: lib.ListParams{
Peername: ref.Peername,
Limit: o.Limit,
Offset: o.Offset,
Limit: listParams.Limit,
Offset: listParams.Offset,
},
}

Expand Down

0 comments on commit 748e58b

Please sign in to comment.