Merge branch '12913-secondary-mounts' refs #12913
[arvados.git] / sdk / go / arvados / collection_fs.go
index 429fabf7b5414c2abb27664324ba8261860d1854..d8ee2a2b1c5175697bf39369274ff6c0a42e7310 100644 (file)
@@ -864,7 +864,7 @@ func (dn *dirnode) loadManifest(txt string) error {
                                return fmt.Errorf("line %d: bad locator %q", lineno, token)
                        }
 
-                       toks := strings.Split(token, ":")
+                       toks := strings.SplitN(token, ":", 3)
                        if len(toks) != 3 {
                                return fmt.Errorf("line %d: bad file segment %q", lineno, token)
                        }
@@ -1078,6 +1078,10 @@ func (dn *dirnode) Rename(oldname, newname string) error {
        if !ok {
                return os.ErrNotExist
        }
+       if locked[oldinode] {
+               // oldinode cannot become a descendant of itself.
+               return ErrInvalidArgument
+       }
        if existing, ok := newdn.inodes[newname]; ok {
                // overwriting an existing file or dir
                if dn, ok := existing.(*dirnode); ok {
@@ -1345,9 +1349,9 @@ func (me *memSegment) ReadAt(p []byte, off int64) (n int, err error) {
 type storedSegment struct {
        kc      keepClient
        locator string
-       size    int
-       offset  int
-       length  int
+       size    int // size of stored block (also encoded in locator)
+       offset  int // position of segment within the stored block
+       length  int // bytes in this segment (offset + length <= size)
 }
 
 func (se storedSegment) Len() int {
@@ -1389,7 +1393,7 @@ func canonicalName(name string) string {
        return name
 }
 
-var manifestEscapeSeq = regexp.MustCompile(`\\([0-9]{3}|\\)`)
+var manifestEscapeSeq = regexp.MustCompile(`\\([0-7]{3}|\\)`)
 
 func manifestUnescapeFunc(seq string) string {
        if seq == `\\` {
@@ -1407,7 +1411,7 @@ func manifestUnescape(s string) string {
        return manifestEscapeSeq.ReplaceAllStringFunc(s, manifestUnescapeFunc)
 }
 
-var manifestEscapedChar = regexp.MustCompile(`[^\.\w/]`)
+var manifestEscapedChar = regexp.MustCompile(`[\000-\040:\s\\]`)
 
 func manifestEscapeFunc(seq string) string {
        return fmt.Sprintf("\\%03o", byte(seq[0]))