diff --git a/context.go b/context.go index 9e72fd0b..2af7101f 100644 --- a/context.go +++ b/context.go @@ -587,7 +587,7 @@ func (c *context) contain(p string) (string, error) { // ZOMBIES(stevvooe): In certain cases, we may want to remap these to a // "containment error", so the caller can decide what to do. - return filepath.Join("/", filepath.Clean(sanitized)), nil + return filepath.Clean(sanitized), nil } // digest returns the digest of the file at path p, relative to the root. diff --git a/manifest.go b/manifest.go index 20706f35..55fbcfb5 100644 --- a/manifest.go +++ b/manifest.go @@ -66,7 +66,7 @@ func BuildManifest(ctx Context) (*Manifest, error) { return fmt.Errorf("error walking %s: %v", p, err) } - if p == "/" { + if p == "." { // skip root return nil } diff --git a/manifest_test.go b/manifest_test.go index 5abe6043..680f271f 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -113,7 +113,7 @@ func TestWalkFS(t *testing.T) { { kind: rdirectory, - path: "/dev", + path: "dev", mode: 0755, }, @@ -311,15 +311,14 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error resourceMap := map[string]Resource{} paths := []string{} for _, r := range resources { - absPath := r.path - if !filepath.IsAbs(absPath) { - absPath = "/" + absPath + if filepath.IsAbs(r.path) { + return nil, fmt.Errorf("path must be relative: %q", r.path) } switch r.kind { case rfile: f := ®ularFile{ resource: resource{ - paths: []string{absPath}, + paths: []string{r.path}, mode: r.mode, uid: r.uid, gid: r.gid, @@ -327,25 +326,24 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error size: int64(r.size), digests: []digest.Digest{r.digest}, } - resourceMap[absPath] = f - paths = append(paths, absPath) + resourceMap[r.path] = f + paths = append(paths, r.path) case rdirectory: d := &directory{ resource: resource{ - paths: []string{absPath}, + paths: []string{r.path}, mode: r.mode, uid: r.uid, gid: r.gid, }, } - resourceMap[absPath] = d - paths = append(paths, absPath) + resourceMap[r.path] = d + paths = append(paths, r.path) case rhardlink: - targetPath := r.target - if !filepath.IsAbs(targetPath) { - targetPath = "/" + targetPath + if filepath.IsAbs(r.target) { + return nil, fmt.Errorf("target must be relative: %q", r.target) } - target, ok := resourceMap[targetPath] + target, ok := resourceMap[r.target] if !ok { return nil, errors.New("must specify target before hardlink for test resources") } @@ -354,7 +352,7 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error return nil, errors.New("hardlink target must be regular file") } // TODO(dmcgowan): full merge - rf.paths = append(rf.paths, absPath) + rf.paths = append(rf.paths, r.path) // TODO(dmcgowan): check if first path is now different, changes source order and should update // resource map key, to avoid canonically ordered first should be regular file sort.Stable(sort.StringSlice(rf.paths)) @@ -366,19 +364,19 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error } s := &symLink{ resource: resource{ - paths: []string{absPath}, + paths: []string{r.path}, mode: r.mode, uid: r.uid, gid: r.gid, }, target: targetPath, } - resourceMap[absPath] = s - paths = append(paths, absPath) + resourceMap[r.path] = s + paths = append(paths, r.path) case rchardev: d := &device{ resource: resource{ - paths: []string{absPath}, + paths: []string{r.path}, mode: r.mode, uid: r.uid, gid: r.gid, @@ -386,19 +384,19 @@ func expectedResourceList(root string, resources []dresource) ([]Resource, error major: uint64(r.major), minor: uint64(r.minor), } - resourceMap[absPath] = d - paths = append(paths, absPath) + resourceMap[r.path] = d + paths = append(paths, r.path) case rnamedpipe: p := &namedPipe{ resource: resource{ - paths: []string{absPath}, + paths: []string{r.path}, mode: r.mode, uid: r.uid, gid: r.gid, }, } - resourceMap[absPath] = p - paths = append(paths, absPath) + resourceMap[r.path] = p + paths = append(paths, r.path) default: return nil, fmt.Errorf("unknown resource type: %v", r.kind) } diff --git a/manifest_test_darwin.go b/manifest_test_darwin.go index 873ec318..c90e8bf8 100644 --- a/manifest_test_darwin.go +++ b/manifest_test_darwin.go @@ -7,7 +7,7 @@ import "os" var ( devNullResource = resource{ kind: chardev, - path: "/dev/null", + path: "dev/null", major: 3, minor: 2, mode: 0666 | os.ModeDevice | os.ModeCharDevice, @@ -15,7 +15,7 @@ var ( devZeroResource = resource{ kind: chardev, - path: "/dev/zero", + path: "dev/zero", major: 3, minor: 3, mode: 0666 | os.ModeDevice | os.ModeCharDevice, diff --git a/proto/manifest.pb.go b/proto/manifest.pb.go index 05107c1d..b8a10167 100644 --- a/proto/manifest.pb.go +++ b/proto/manifest.pb.go @@ -52,7 +52,9 @@ func (m *Manifest) GetResource() []*Resource { type Resource struct { // Path specifies the path from the bundle root. If more than one // path is present, the entry may represent a hardlink, rather than using - // a link target. The path format is operating system specific. + // a link target. + // A path must be relative to the bundle root. + // TODO(AkihiroSuda): use '/' seperator regardless of the operating system used for building the manifest? Path []string `protobuf:"bytes,1,rep,name=path" json:"path,omitempty"` // Uid specifies the user id for the resource. Uid int64 `protobuf:"varint,2,opt,name=uid" json:"uid,omitempty"` diff --git a/proto/manifest.proto b/proto/manifest.proto index 844ea791..f4bbd51d 100644 --- a/proto/manifest.proto +++ b/proto/manifest.proto @@ -11,7 +11,9 @@ message Manifest { message Resource { // Path specifies the path from the bundle root. If more than one // path is present, the entry may represent a hardlink, rather than using - // a link target. The path format is operating system specific. + // a link target. + // A path must be relative to the bundle root. + // TODO(AkihiroSuda): use '/' seperator regardless of the operating system used for building the manifest? repeated string path = 1; // NOTE(stevvooe): Need to define clear precedence for user/group/uid/gid precedence.