-func (m *SegmentedManifest) ManifestForPath(path, relocate string) string {
- if path == "" {
- path = "."
- }
- if relocate == "" {
- relocate = "."
- }
-
- streamname, filename := SplitPath(path)
- var relocate_stream, relocate_filename string
- relocate_stream, relocate_filename = SplitPath(relocate)
-
- if stream, ok := (*m)[path]; ok {
- // refers to a single stream
- return stream.NormalizeStream(relocate)
- } else if stream, ok := (*m)[streamname]; ok {
- // refers to a single file in a stream
- newstream := make(SegmentedStream)
- if relocate_filename == "" {
- relocate_filename = filename
- }
- newstream[relocate_filename] = stream[filename]
- return newstream.NormalizeStream(relocate_stream)
- } else {
- // refers to multiple streams
- manifest := ""
- prefix := path
- if !strings.HasSuffix(prefix, "/") {
- prefix += "/"
- }
- if !strings.HasSuffix(relocate, "/") {
- relocate += "/"
- }
-
- var sortedstreams []string
- for k, _ := range *m {
- sortedstreams = append(sortedstreams, k)
- }
- sort.Strings(sortedstreams)
-
- for _, k := range sortedstreams {
- if strings.HasPrefix(k, prefix) {
- v := (*m)[k]
- manifest += v.NormalizeStream(relocate + k[len(prefix):])
- }
- }
- return manifest
+// Extract extracts some or all of the manifest and returns the extracted
+// portion as a normalized manifest. This is a swiss army knife function that
+// can be several ways:
+//
+// If 'srcpath' and 'relocate' are '.' it simply returns an equivalent manifest
+// in normalized form.
+//
+// Extract(".", ".") // return entire normalized manfest text
+//
+// If 'srcpath' points to a single file, it will return manifest text for just that file.
+// The value of "relocate" is can be used to rename the file or set the file stream.
+//
+// Extract("./foo", ".") // extract file "foo" and put it in stream "."
+// Extract("./foo", "./bar") // extract file "foo", rename it to "bar" in stream "."
+// Extract("./foo", "./bar/") // extract file "foo", rename it to "./bar/foo"
+// Extract("./foo", "./bar/baz") // extract file "foo", rename it to "./bar/baz")
+//
+// Otherwise it will return the manifest text for all streams with the prefix in "srcpath" and place
+// them under the path in "relocate".
+//
+// Extract("./stream", ".") // extract "./stream" to "." and "./stream/subdir" to "./subdir")
+// Extract("./stream", "./bar") // extract "./stream" to "./bar" and "./stream/subdir" to "./bar/subdir")
+func (m Manifest) Extract(srcpath, relocate string) (ret Manifest) {
+ segmented, err := m.segment()
+ if err != nil {
+ ret.Err = err
+ return