diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-05-07 14:07:11 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-05-07 14:07:11 +0200 |
| commit | b65158017829cee6fba71a6d730d1502026280a7 (patch) | |
| tree | 6318a38ffd63d8788a1795b3a5bd7ee8286e05ea /object_iterator.go | |
| parent | 17e9003342f79313d4b919818db6f69964d102db (diff) | |
| download | go-schwift-b65158017829cee6fba71a6d730d1502026280a7.tar.gz | |
add support for symlinks to ObjectIterator
Closes #2.
Diffstat (limited to 'object_iterator.go')
| -rw-r--r-- | object_iterator.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/object_iterator.go b/object_iterator.go index 6231292..a94d7c9 100644 --- a/object_iterator.go +++ b/object_iterator.go @@ -20,6 +20,7 @@ package schwift import ( "fmt" + "regexp" "time" ) @@ -33,6 +34,8 @@ type ObjectInfo struct { ContentType string Etag string LastModified time.Time + //SymlinkTarget is only set for symlinks. + SymlinkTarget *Object //If the ObjectInfo refers to an actual object, then SubDirectory is empty. //If the ObjectInfo refers to a pseudo-directory, then SubDirectory contains //the path of the pseudo-directory and all other fields are nil/zero/empty. @@ -113,6 +116,9 @@ func (i *ObjectIterator) NextPage(limit int) ([]*Object, error) { return result, nil } +//The symlink_path attribute looks like "/v1/AUTH_foo/containername/obje/ctna/me". +var symlinkPathRx = regexp.MustCompile(`^/v1/([^/]+)/([^/]+)/(.+)$`) + //NextPageDetailed is like NextPage, but includes basic metadata. func (i *ObjectIterator) NextPageDetailed(limit int) ([]ObjectInfo, error) { b := i.getBase() @@ -124,6 +130,7 @@ func (i *ObjectIterator) NextPageDetailed(limit int) ([]ObjectInfo, error) { Etag string `json:"hash"` LastModifiedStr string `json:"last_modified"` Name string `json:"name"` + SymlinkPath string `json:"symlink_path"` //or just this: Subdir string `json:"subdir"` } @@ -150,6 +157,18 @@ func (i *ObjectIterator) NextPageDetailed(limit int) ([]ObjectInfo, error) { //this error is sufficiently obscure that we don't need to expose a type for it return nil, fmt.Errorf("Bad field objects[%d].last_modified: %s", idx, err.Error()) } + if data.SymlinkPath != "" { + match := symlinkPathRx.FindStringSubmatch(data.SymlinkPath) + if match == nil { + //like above + return nil, fmt.Errorf("Bad field objects[%d].symlink_path: %q", idx, data.SymlinkPath) + } + a := i.Container.a + if a.Name() != match[1] { + a = a.SwitchAccount(match[1]) + } + result[idx].SymlinkTarget = a.Container(match[2]).Object(match[3]) + } } else { marker = data.Subdir result[idx].SubDirectory = data.Subdir |
