Skip to content

Commit

Permalink
Fixed REST mgmt file list
Browse files Browse the repository at this point in the history
It seems that the DataPower REST mgmt responses or `jsonquery`
behaviour changed at some point and the result was that the list
of files and directories had blank entries and duplicates.
  • Loading branch information
vvidovic-croz committed May 22, 2023
1 parent 4c266ee commit 7b90648
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions repo/dp/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2334,8 +2334,11 @@ func (r *dpRepo) listFiles(selectedItemConfig *model.ItemConfig) ([]model.Item,
return nil, err
}

// "//" - work-around - for one directory we get JSON object, for multiple directories we get JSON array
dirNodes := jsonquery.Find(doc, "/filestore/location/directory//name/..")
// double-find - work-around - for one directory we get JSON object, for multiple directories we get JSON array
dirNodes := jsonquery.Find(doc, "/filestore/location/directory/name/..")
if len(dirNodes) == 0 {
dirNodes = jsonquery.Find(doc, "/filestore/location/directory/*/name/..")
}
for _, n := range dirNodes {
dirDpPath := n.SelectElement("name").InnerText()
_, dirName := splitOnLast(dirDpPath, "/")
Expand All @@ -2350,8 +2353,11 @@ func (r *dpRepo) listFiles(selectedItemConfig *model.ItemConfig) ([]model.Item,
items = append(items, item)
}

// "//" - work-around - for one file we get JSON object, for multiple files we get JSON array
fileNodes := jsonquery.Find(doc, "/filestore/location/file//name/..")
// double-find - work-around - for one file we get JSON object, for multiple files we get JSON array
fileNodes := jsonquery.Find(doc, "/filestore/location/file/name/..")
if len(fileNodes) == 0 {
fileNodes = jsonquery.Find(doc, "/filestore/location/file/*/name/..")
}
for _, n := range fileNodes {
fileName := n.SelectElement("name").InnerText()
fileSize := n.SelectElement("size").InnerText()
Expand Down

0 comments on commit 7b90648

Please sign in to comment.