- var collection arvados.Collection
- err := runner.ArvClient.Get("collections", mnt.PortableDataHash, nil, &collection)
- if err != nil {
- return "", fmt.Errorf("While getting collection for %v: %v", mnt.PortableDataHash, err)
- }
-
- manifestText := ""
- if mnt.Path == "" {
- // no path specified; return the entire manifest text
- manifestText = collection.ManifestText
- manifestText = strings.Replace(manifestText, "./", "."+bindSuffix+"/", -1)
- manifestText = strings.Replace(manifestText, ". ", "."+bindSuffix+" ", -1)
- } else {
- // either a single stream or file from a stream is being sought
- bindIdx := strings.LastIndex(bindSuffix, "/")
- var bindSubdir, bindFileName string
- if bindIdx >= 0 {
- bindSubdir = bindSuffix[0:bindIdx]
- bindFileName = bindSuffix[bindIdx+1:]
- }
- pathIdx := strings.LastIndex(mnt.Path, "/")
- var pathSubdir, pathFileName string
- if pathIdx >= 0 {
- pathSubdir = mnt.Path[0:pathIdx]
- pathFileName = mnt.Path[pathIdx+1:]
- }
- streams := strings.Split(collection.ManifestText, "\n")
- for _, stream := range streams {
- tokens := strings.Split(stream, " ")
- if tokens[0] == "."+mnt.Path {
- // path refers to this stream
- adjustedStream := strings.Replace(stream, mnt.Path, bindSuffix, -1)
- manifestText = adjustedStream + "\n"
- break
- } else {
- // look for a matching file in this stream
- if tokens[0] == "."+pathSubdir {
- // path refers to a file in this stream
- for _, token := range tokens {
- if strings.Index(token, ":"+pathFileName) > 0 {
- // found the file in the stream; discard all other file tokens
- for _, t := range tokens {
- if strings.Index(t, ":") == -1 {
- manifestText += (" " + t)
- } else {
- break // done reading all non-file tokens
- }
- }
- manifestText = strings.Trim(manifestText, " ")
- token = strings.Replace(token, pathFileName, bindFileName, -1)
- manifestText += (" " + token + "\n")
- manifestText = strings.Replace(manifestText, pathSubdir, bindSubdir, -1)
- break
- }
- }
- }
- }