1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
22 var maxBlockSize = 1 << 26
24 var concurrentWriters = 4
26 // A CollectionFileSystem is a FileSystem that can be serialized as a
27 // manifest and stored as a collection.
28 type CollectionFileSystem interface {
31 // Flush all file data to Keep and return a snapshot of the
32 // filesystem suitable for saving as (Collection)ManifestText.
33 // Prefix (normally ".") is a top level directory, effectively
34 // prepended to all paths in the returned manifest.
35 MarshalManifest(prefix string) (string, error)
37 // Total data bytes in all files.
41 type collectionFileSystem struct {
46 // FileSystem returns a CollectionFileSystem for the collection.
47 func (c *Collection) FileSystem(client apiClient, kc keepClient) (CollectionFileSystem, error) {
49 if c.ModifiedAt == nil {
52 modTime = *c.ModifiedAt
54 fs := &collectionFileSystem{
56 fileSystem: fileSystem{
57 fsBackend: keepBackend{apiClient: client, keepClient: kc},
65 mode: os.ModeDir | 0755,
68 inodes: make(map[string]inode),
71 root.SetParent(root, ".")
72 if err := root.loadManifest(c.ManifestText); err != nil {
75 backdateTree(root, modTime)
80 func backdateTree(n inode, modTime time.Time) {
81 switch n := n.(type) {
83 n.fileinfo.modTime = modTime
85 n.fileinfo.modTime = modTime
86 for _, n := range n.inodes {
87 backdateTree(n, modTime)
92 func (fs *collectionFileSystem) newNode(name string, perm os.FileMode, modTime time.Time) (node inode, err error) {
93 if name == "" || name == "." || name == ".." {
94 return nil, ErrInvalidArgument
102 mode: perm | os.ModeDir,
105 inodes: make(map[string]inode),
113 mode: perm & ^os.ModeDir,
120 func (fs *collectionFileSystem) Sync() error {
124 txt, err := fs.MarshalManifest(".")
126 return fmt.Errorf("sync failed: %s", err)
132 err = fs.RequestAndDecode(nil, "PUT", "arvados/v1/collections/"+fs.uuid, fs.UpdateBody(coll), map[string]interface{}{"select": []string{"uuid"}})
134 return fmt.Errorf("sync failed: update %s: %s", fs.uuid, err)
139 func (fs *collectionFileSystem) MarshalManifest(prefix string) (string, error) {
140 fs.fileSystem.root.Lock()
141 defer fs.fileSystem.root.Unlock()
142 return fs.fileSystem.root.(*dirnode).marshalManifest(context.TODO(), prefix, newThrottle(concurrentWriters))
145 func (fs *collectionFileSystem) Size() int64 {
146 return fs.fileSystem.root.(*dirnode).TreeSize()
149 // filenodePtr is an offset into a file that is (usually) efficient to
150 // seek to. Specifically, if filenode.repacked==filenodePtr.repacked
152 // filenode.segments[filenodePtr.segmentIdx][filenodePtr.segmentOff]
153 // corresponds to file offset filenodePtr.off. Otherwise, it is
154 // necessary to reexamine len(filenode.segments[0]) etc. to find the
155 // correct segment and offset.
156 type filenodePtr struct {
163 // seek returns a ptr that is consistent with both startPtr.off and
164 // the current state of fn. The caller must already hold fn.RLock() or
167 // If startPtr is beyond EOF, ptr.segment* will indicate precisely
172 // ptr.segmentIdx == len(filenode.segments) // i.e., at EOF
174 // filenode.segments[ptr.segmentIdx].Len() > ptr.segmentOff
175 func (fn *filenode) seek(startPtr filenodePtr) (ptr filenodePtr) {
178 // meaningless anyway
180 } else if ptr.off >= fn.fileinfo.size {
181 ptr.segmentIdx = len(fn.segments)
183 ptr.repacked = fn.repacked
185 } else if ptr.repacked == fn.repacked {
186 // segmentIdx and segmentOff accurately reflect
187 // ptr.off, but might have fallen off the end of a
189 if ptr.segmentOff >= fn.segments[ptr.segmentIdx].Len() {
196 ptr.repacked = fn.repacked
198 if ptr.off >= fn.fileinfo.size {
199 ptr.segmentIdx, ptr.segmentOff = len(fn.segments), 0
202 // Recompute segmentIdx and segmentOff. We have already
203 // established fn.fileinfo.size > ptr.off >= 0, so we don't
204 // have to deal with edge cases here.
206 for ptr.segmentIdx, ptr.segmentOff = 0, 0; off < ptr.off; ptr.segmentIdx++ {
207 // This would panic (index out of range) if
208 // fn.fileinfo.size were larger than
209 // sum(fn.segments[i].Len()) -- but that can't happen
210 // because we have ensured fn.fileinfo.size is always
212 segLen := int64(fn.segments[ptr.segmentIdx].Len())
213 if off+segLen > ptr.off {
214 ptr.segmentOff = int(ptr.off - off)
222 // filenode implements inode.
223 type filenode struct {
228 // number of times `segments` has changed in a
229 // way that might invalidate a filenodePtr
231 memsize int64 // bytes in memSegments
236 // caller must have lock
237 func (fn *filenode) appendSegment(e segment) {
238 fn.segments = append(fn.segments, e)
239 fn.fileinfo.size += int64(e.Len())
242 func (fn *filenode) SetParent(p inode, name string) {
246 fn.fileinfo.name = name
249 func (fn *filenode) Parent() inode {
255 func (fn *filenode) FS() FileSystem {
259 // Read reads file data from a single segment, starting at startPtr,
260 // into p. startPtr is assumed not to be up-to-date. Caller must have
262 func (fn *filenode) Read(p []byte, startPtr filenodePtr) (n int, ptr filenodePtr, err error) {
263 ptr = fn.seek(startPtr)
265 err = ErrNegativeOffset
268 if ptr.segmentIdx >= len(fn.segments) {
272 n, err = fn.segments[ptr.segmentIdx].ReadAt(p, int64(ptr.segmentOff))
276 if ptr.segmentOff == fn.segments[ptr.segmentIdx].Len() {
279 if ptr.segmentIdx < len(fn.segments) && err == io.EOF {
287 func (fn *filenode) Size() int64 {
290 return fn.fileinfo.Size()
293 func (fn *filenode) FileInfo() os.FileInfo {
299 func (fn *filenode) Truncate(size int64) error {
302 return fn.truncate(size)
305 func (fn *filenode) truncate(size int64) error {
306 if size == fn.fileinfo.size {
310 if size < fn.fileinfo.size {
311 ptr := fn.seek(filenodePtr{off: size})
312 for i := ptr.segmentIdx; i < len(fn.segments); i++ {
313 if seg, ok := fn.segments[i].(*memSegment); ok {
314 fn.memsize -= int64(seg.Len())
317 if ptr.segmentOff == 0 {
318 fn.segments = fn.segments[:ptr.segmentIdx]
320 fn.segments = fn.segments[:ptr.segmentIdx+1]
321 switch seg := fn.segments[ptr.segmentIdx].(type) {
323 seg.Truncate(ptr.segmentOff)
324 fn.memsize += int64(seg.Len())
326 fn.segments[ptr.segmentIdx] = seg.Slice(0, ptr.segmentOff)
329 fn.fileinfo.size = size
332 for size > fn.fileinfo.size {
333 grow := size - fn.fileinfo.size
336 if len(fn.segments) == 0 {
338 fn.segments = append(fn.segments, seg)
339 } else if seg, ok = fn.segments[len(fn.segments)-1].(*memSegment); !ok || seg.Len() >= maxBlockSize {
341 fn.segments = append(fn.segments, seg)
343 if maxgrow := int64(maxBlockSize - seg.Len()); maxgrow < grow {
346 seg.Truncate(seg.Len() + int(grow))
347 fn.fileinfo.size += grow
353 // Write writes data from p to the file, starting at startPtr,
354 // extending the file size if necessary. Caller must have Lock.
355 func (fn *filenode) Write(p []byte, startPtr filenodePtr) (n int, ptr filenodePtr, err error) {
356 if startPtr.off > fn.fileinfo.size {
357 if err = fn.truncate(startPtr.off); err != nil {
358 return 0, startPtr, err
361 ptr = fn.seek(startPtr)
363 err = ErrNegativeOffset
366 for len(p) > 0 && err == nil {
368 if len(cando) > maxBlockSize {
369 cando = cando[:maxBlockSize]
371 // Rearrange/grow fn.segments (and shrink cando if
372 // needed) such that cando can be copied to
373 // fn.segments[ptr.segmentIdx] at offset
375 cur := ptr.segmentIdx
376 prev := ptr.segmentIdx - 1
378 if cur < len(fn.segments) {
379 _, curWritable = fn.segments[cur].(*memSegment)
381 var prevAppendable bool
382 if prev >= 0 && fn.segments[prev].Len() < maxBlockSize {
383 _, prevAppendable = fn.segments[prev].(*memSegment)
385 if ptr.segmentOff > 0 && !curWritable {
386 // Split a non-writable block.
387 if max := fn.segments[cur].Len() - ptr.segmentOff; max <= len(cando) {
388 // Truncate cur, and insert a new
391 fn.segments = append(fn.segments, nil)
392 copy(fn.segments[cur+1:], fn.segments[cur:])
394 // Split cur into two copies, truncate
395 // the one on the left, shift the one
396 // on the right, and insert a new
397 // segment between them.
398 fn.segments = append(fn.segments, nil, nil)
399 copy(fn.segments[cur+2:], fn.segments[cur:])
400 fn.segments[cur+2] = fn.segments[cur+2].Slice(ptr.segmentOff+len(cando), -1)
405 seg.Truncate(len(cando))
406 fn.memsize += int64(len(cando))
407 fn.segments[cur] = seg
408 fn.segments[prev] = fn.segments[prev].Slice(0, ptr.segmentOff)
413 } else if curWritable {
414 if fit := int(fn.segments[cur].Len()) - ptr.segmentOff; fit < len(cando) {
419 // Shrink cando if needed to fit in
421 if cangrow := maxBlockSize - fn.segments[prev].Len(); cangrow < len(cando) {
422 cando = cando[:cangrow]
426 if cur == len(fn.segments) {
427 // ptr is at EOF, filesize is changing.
428 fn.fileinfo.size += int64(len(cando))
429 } else if el := fn.segments[cur].Len(); el <= len(cando) {
430 // cando is long enough that we won't
431 // need cur any more. shrink cando to
432 // be exactly as long as cur
433 // (otherwise we'd accidentally shift
434 // the effective position of all
435 // segments after cur).
437 copy(fn.segments[cur:], fn.segments[cur+1:])
438 fn.segments = fn.segments[:len(fn.segments)-1]
440 // shrink cur by the same #bytes we're growing prev
441 fn.segments[cur] = fn.segments[cur].Slice(len(cando), -1)
447 ptr.segmentOff = fn.segments[prev].Len()
448 fn.segments[prev].(*memSegment).Truncate(ptr.segmentOff + len(cando))
449 fn.memsize += int64(len(cando))
453 // Insert a segment between prev and
454 // cur, and advance prev/cur.
455 fn.segments = append(fn.segments, nil)
456 if cur < len(fn.segments) {
457 copy(fn.segments[cur+1:], fn.segments[cur:])
461 // appending a new segment does
462 // not invalidate any ptrs
465 seg.Truncate(len(cando))
466 fn.memsize += int64(len(cando))
467 fn.segments[cur] = seg
473 // Finally we can copy bytes from cando to the current segment.
474 fn.segments[ptr.segmentIdx].(*memSegment).WriteAt(cando, ptr.segmentOff)
478 ptr.off += int64(len(cando))
479 ptr.segmentOff += len(cando)
480 if ptr.segmentOff >= maxBlockSize {
481 fn.pruneMemSegments()
483 if fn.segments[ptr.segmentIdx].Len() == ptr.segmentOff {
488 fn.fileinfo.modTime = time.Now()
493 // Write some data out to disk to reduce memory use. Caller must have
495 func (fn *filenode) pruneMemSegments() {
496 // TODO: async (don't hold Lock() while waiting for Keep)
497 // TODO: share code with (*dirnode)sync()
498 // TODO: pack/flush small blocks too, when fragmented
499 for idx, seg := range fn.segments {
500 seg, ok := seg.(*memSegment)
501 if !ok || seg.Len() < maxBlockSize {
504 locator, _, err := fn.FS().PutB(seg.buf)
506 // TODO: stall (or return errors from)
507 // subsequent writes until flushing
511 fn.memsize -= int64(seg.Len())
512 fn.segments[idx] = storedSegment{
522 type dirnode struct {
523 fs *collectionFileSystem
527 func (dn *dirnode) FS() FileSystem {
531 func (dn *dirnode) Child(name string, replace func(inode) (inode, error)) (inode, error) {
532 if dn == dn.fs.rootnode() && name == ".arvados#collection" {
533 gn := &getternode{Getter: func() ([]byte, error) {
536 coll.ManifestText, err = dn.fs.MarshalManifest(".")
540 data, err := json.Marshal(&coll)
542 data = append(data, '\n')
546 gn.SetParent(dn, name)
549 return dn.treenode.Child(name, replace)
552 // sync flushes in-memory data and remote block references (for the
553 // children with the given names, which must be children of dn) to
554 // local persistent storage. Caller must have write lock on dn and the
556 func (dn *dirnode) sync(ctx context.Context, names []string, throttle *throttle) error {
557 ctx, cancel := context.WithCancel(ctx)
560 type shortBlock struct {
564 var pending []shortBlock
567 errors := make(chan error, 1)
568 var wg sync.WaitGroup
569 defer wg.Wait() // we have locks: unsafe to return until all goroutines finish
571 flush := func(sbs []shortBlock) {
577 defer throttle.Release()
578 if ctx.Err() != nil {
581 block := make([]byte, 0, maxBlockSize)
582 for _, sb := range sbs {
583 block = append(block, sb.fn.segments[sb.idx].(*memSegment).buf...)
585 locator, _, err := dn.fs.PutB(block)
594 for _, sb := range sbs {
595 data := sb.fn.segments[sb.idx].(*memSegment).buf
596 sb.fn.segments[sb.idx] = storedSegment{
604 sb.fn.memsize -= int64(len(data))
608 localLocator := map[string]string{}
609 for _, name := range names {
610 fn, ok := dn.inodes[name].(*filenode)
614 for idx, seg := range fn.segments {
615 switch seg := seg.(type) {
617 loc, ok := localLocator[seg.locator]
620 loc, err = dn.fs.LocalLocator(seg.locator)
624 localLocator[seg.locator] = loc
627 fn.segments[idx] = seg
629 if seg.Len() > maxBlockSize/2 {
631 go flush([]shortBlock{{fn, idx}})
634 if pendingLen+seg.Len() > maxBlockSize {
640 pending = append(pending, shortBlock{fn, idx})
641 pendingLen += seg.Len()
643 panic(fmt.Sprintf("can't sync segment type %T", seg))
656 // caller must have write lock.
657 func (dn *dirnode) marshalManifest(ctx context.Context, prefix string, throttle *throttle) (string, error) {
658 ctx, cancel := context.WithCancel(ctx)
661 if len(dn.inodes) == 0 {
665 // Express the existence of an empty directory by
666 // adding an empty file named `\056`, which (unlike
667 // the more obvious spelling `.`) is accepted by the
668 // API's manifest validator.
669 return manifestEscape(prefix) + " d41d8cd98f00b204e9800998ecf8427e+0 0:0:\\056\n", nil
672 names := make([]string, 0, len(dn.inodes))
673 for name := range dn.inodes {
674 names = append(names, name)
677 var dirnames []string
678 var filenames []string
679 for _, name := range names {
680 node := dn.inodes[name]
683 switch node := node.(type) {
685 dirnames = append(dirnames, name)
687 filenames = append(filenames, name)
689 panic(fmt.Sprintf("can't marshal inode type %T", node))
693 var wg sync.WaitGroup
694 errors := make(chan error, len(dirnames)+1)
695 subdirs := make([]string, len(dirnames))
697 for i, name := range dirnames {
699 go func(i int, name string) {
702 subdirs[i], err = dn.inodes[name].(*dirnode).marshalManifest(ctx, prefix+"/"+name, throttle)
715 type filepart struct {
721 var fileparts []filepart
723 if err := dn.sync(ctx, names, throttle); err != nil {
728 for _, name := range filenames {
729 node := dn.inodes[name].(*filenode)
730 if len(node.segments) == 0 {
731 fileparts = append(fileparts, filepart{name: name})
734 for _, seg := range node.segments {
735 switch seg := seg.(type) {
737 if len(blocks) > 0 && blocks[len(blocks)-1] == seg.locator {
738 streamLen -= int64(seg.size)
740 blocks = append(blocks, seg.locator)
744 offset: streamLen + int64(seg.offset),
745 length: int64(seg.length),
747 if prev := len(fileparts) - 1; prev >= 0 &&
748 fileparts[prev].name == name &&
749 fileparts[prev].offset+fileparts[prev].length == next.offset {
750 fileparts[prev].length += next.length
752 fileparts = append(fileparts, next)
754 streamLen += int64(seg.size)
756 // This can't happen: we
757 // haven't unlocked since
759 panic(fmt.Sprintf("can't marshal segment type %T", seg))
763 var filetokens []string
764 for _, s := range fileparts {
765 filetokens = append(filetokens, fmt.Sprintf("%d:%d:%s", s.offset, s.length, manifestEscape(s.name)))
767 if len(filetokens) == 0 {
769 } else if len(blocks) == 0 {
770 blocks = []string{"d41d8cd98f00b204e9800998ecf8427e+0"}
772 rootdir = manifestEscape(prefix) + " " + strings.Join(blocks, " ") + " " + strings.Join(filetokens, " ") + "\n"
777 case err := <-errors:
781 return rootdir + strings.Join(subdirs, ""), nil
784 func (dn *dirnode) loadManifest(txt string) error {
786 streams := strings.Split(txt, "\n")
787 if streams[len(streams)-1] != "" {
788 return fmt.Errorf("line %d: no trailing newline", len(streams))
790 streams = streams[:len(streams)-1]
791 segments := []storedSegment{}
792 for i, stream := range streams {
794 var anyFileTokens bool
797 segments = segments[:0]
798 for i, token := range strings.Split(stream, " ") {
800 dirname = manifestUnescape(token)
803 if !strings.Contains(token, ":") {
805 return fmt.Errorf("line %d: bad file segment %q", lineno, token)
807 toks := strings.SplitN(token, "+", 3)
809 return fmt.Errorf("line %d: bad locator %q", lineno, token)
811 length, err := strconv.ParseInt(toks[1], 10, 32)
812 if err != nil || length < 0 {
813 return fmt.Errorf("line %d: bad locator %q", lineno, token)
815 segments = append(segments, storedSegment{
822 } else if len(segments) == 0 {
823 return fmt.Errorf("line %d: bad locator %q", lineno, token)
826 toks := strings.SplitN(token, ":", 3)
828 return fmt.Errorf("line %d: bad file segment %q", lineno, token)
832 offset, err := strconv.ParseInt(toks[0], 10, 64)
833 if err != nil || offset < 0 {
834 return fmt.Errorf("line %d: bad file segment %q", lineno, token)
836 length, err := strconv.ParseInt(toks[1], 10, 64)
837 if err != nil || length < 0 {
838 return fmt.Errorf("line %d: bad file segment %q", lineno, token)
840 name := dirname + "/" + manifestUnescape(toks[2])
841 fnode, err := dn.createFileAndParents(name)
842 if fnode == nil && err == nil && length == 0 {
843 // Special case: an empty file used as
844 // a marker to preserve an otherwise
845 // empty directory in a manifest.
848 if err != nil || (fnode == nil && length != 0) {
849 return fmt.Errorf("line %d: cannot use path %q with length %d: %s", lineno, name, length, err)
851 // Map the stream offset/range coordinates to
852 // block/offset/range coordinates and add
853 // corresponding storedSegments to the filenode
855 // Can't continue where we left off.
856 // TODO: binary search instead of
857 // rewinding all the way (but this
858 // situation might be rare anyway)
861 for next := int64(0); segIdx < len(segments); segIdx++ {
862 seg := segments[segIdx]
863 next = pos + int64(seg.Len())
864 if next <= offset || seg.Len() == 0 {
868 if pos >= offset+length {
873 blkOff = int(offset - pos)
875 blkLen := seg.Len() - blkOff
876 if pos+int64(blkOff+blkLen) > offset+length {
877 blkLen = int(offset + length - pos - int64(blkOff))
879 fnode.appendSegment(storedSegment{
881 locator: seg.locator,
886 if next > offset+length {
892 if segIdx == len(segments) && pos < offset+length {
893 return fmt.Errorf("line %d: invalid segment in %d-byte stream: %q", lineno, pos, token)
897 return fmt.Errorf("line %d: no file segments", lineno)
898 } else if len(segments) == 0 {
899 return fmt.Errorf("line %d: no locators", lineno)
900 } else if dirname == "" {
901 return fmt.Errorf("line %d: no stream name", lineno)
907 // only safe to call from loadManifest -- no locking.
909 // If path is a "parent directory exists" marker (the last path
910 // component is "."), the returned values are both nil.
911 func (dn *dirnode) createFileAndParents(path string) (fn *filenode, err error) {
913 names := strings.Split(path, "/")
914 basename := names[len(names)-1]
915 for _, name := range names[:len(names)-1] {
921 // can't be sure parent will be a *dirnode
922 return nil, ErrInvalidArgument
927 node, err = node.Child(name, func(child inode) (inode, error) {
929 child, err := node.FS().newNode(name, 0755|os.ModeDir, node.Parent().FileInfo().ModTime())
933 child.SetParent(node, name)
935 } else if !child.IsDir() {
936 return child, ErrFileExists
947 } else if !permittedName(basename) {
948 err = fmt.Errorf("invalid file part %q in path %q", basename, path)
951 _, err = node.Child(basename, func(child inode) (inode, error) {
952 switch child := child.(type) {
954 child, err = node.FS().newNode(basename, 0755, node.FileInfo().ModTime())
958 child.SetParent(node, basename)
959 fn = child.(*filenode)
965 return child, ErrIsDirectory
967 return child, ErrInvalidArgument
973 func (dn *dirnode) TreeSize() (bytes int64) {
976 for _, i := range dn.inodes {
977 switch i := i.(type) {
981 bytes += i.TreeSize()
987 type segment interface {
990 // Return a new segment with a subsection of the data from this
991 // one. length<0 means length=Len()-off.
992 Slice(off int, length int) segment
995 type memSegment struct {
999 func (me *memSegment) Len() int {
1003 func (me *memSegment) Slice(off, length int) segment {
1005 length = len(me.buf) - off
1007 buf := make([]byte, length)
1008 copy(buf, me.buf[off:])
1009 return &memSegment{buf: buf}
1012 func (me *memSegment) Truncate(n int) {
1013 if n > cap(me.buf) {
1016 newsize = newsize << 2
1018 newbuf := make([]byte, n, newsize)
1019 copy(newbuf, me.buf)
1022 // Zero unused part when shrinking, in case we grow
1023 // and start using it again later.
1024 for i := n; i < len(me.buf); i++ {
1031 func (me *memSegment) WriteAt(p []byte, off int) {
1032 if off+len(p) > len(me.buf) {
1033 panic("overflowed segment")
1035 copy(me.buf[off:], p)
1038 func (me *memSegment) ReadAt(p []byte, off int64) (n int, err error) {
1039 if off > int64(me.Len()) {
1043 n = copy(p, me.buf[int(off):])
1050 type storedSegment struct {
1053 size int // size of stored block (also encoded in locator)
1054 offset int // position of segment within the stored block
1055 length int // bytes in this segment (offset + length <= size)
1058 func (se storedSegment) Len() int {
1062 func (se storedSegment) Slice(n, size int) segment {
1065 if size >= 0 && se.length > size {
1071 func (se storedSegment) ReadAt(p []byte, off int64) (n int, err error) {
1072 if off > int64(se.length) {
1075 maxlen := se.length - int(off)
1076 if len(p) > maxlen {
1078 n, err = se.kc.ReadAt(se.locator, p, int(off)+se.offset)
1084 return se.kc.ReadAt(se.locator, p, int(off)+se.offset)
1087 func canonicalName(name string) string {
1088 name = path.Clean("/" + name)
1089 if name == "/" || name == "./" {
1091 } else if strings.HasPrefix(name, "/") {
1097 var manifestEscapeSeq = regexp.MustCompile(`\\([0-7]{3}|\\)`)
1099 func manifestUnescapeFunc(seq string) string {
1103 i, err := strconv.ParseUint(seq[1:], 8, 8)
1105 // Invalid escape sequence: can't unescape.
1108 return string([]byte{byte(i)})
1111 func manifestUnescape(s string) string {
1112 return manifestEscapeSeq.ReplaceAllStringFunc(s, manifestUnescapeFunc)
1115 var manifestEscapedChar = regexp.MustCompile(`[\000-\040:\s\\]`)
1117 func manifestEscapeFunc(seq string) string {
1118 return fmt.Sprintf("\\%03o", byte(seq[0]))
1121 func manifestEscape(s string) string {
1122 return manifestEscapedChar.ReplaceAllStringFunc(s, manifestEscapeFunc)