mirror of https://github.com/docker/cli.git
Bump containerd client to d97a907f7f781c0ab8340877d8e6b53cc7f1c2f6
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
943a2d1065
commit
036b8f75e5
|
@ -3,8 +3,8 @@ github.com/asaskevich/govalidator f9ffefc3facfbe0caee3fea233cbb6e8208f4541
|
||||||
github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109
|
github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109
|
||||||
github.com/beorn7/perks 3a771d992973f24aa725d07868b467d1ddfceafb
|
github.com/beorn7/perks 3a771d992973f24aa725d07868b467d1ddfceafb
|
||||||
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
|
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
|
||||||
github.com/containerd/containerd bb0f83ab6eec47c3316bb763d5c20a82c7750c31
|
github.com/containerd/containerd d97a907f7f781c0ab8340877d8e6b53cc7f1c2f6
|
||||||
github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371
|
github.com/containerd/continuity f44b615e492bdfb371aae2f76ec694d9da1db537
|
||||||
github.com/containerd/fifo 3d5202a
|
github.com/containerd/fifo 3d5202a
|
||||||
github.com/containerd/typeurl f694355
|
github.com/containerd/typeurl f694355
|
||||||
github.com/coreos/etcd v3.3.9
|
github.com/coreos/etcd v3.3.9
|
||||||
|
@ -44,7 +44,7 @@ github.com/hashicorp/golang-lru 0fb14efe8c47ae851c0034ed7a448854d3d34cf3
|
||||||
github.com/hashicorp/go-version 23480c0
|
github.com/hashicorp/go-version 23480c0
|
||||||
github.com/imdario/mergo v0.3.6
|
github.com/imdario/mergo v0.3.6
|
||||||
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0
|
github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 # v1.0
|
||||||
github.com/json-iterator/go ab8a2e0c74be9d3be70b3184d9acc634935ded82 # 1.1.4
|
github.com/json-iterator/go 1624edc4454b8682399def8740d46db5e4362ba4 # 1.1.5
|
||||||
github.com/mattn/go-shellwords v1.0.3
|
github.com/mattn/go-shellwords v1.0.3
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1
|
github.com/matttproud/golang_protobuf_extensions v1.0.1
|
||||||
github.com/Microsoft/hcsshim v0.7.3
|
github.com/Microsoft/hcsshim v0.7.3
|
||||||
|
|
|
@ -224,7 +224,7 @@ This will be the best place to discuss design and implementation.
|
||||||
|
|
||||||
For sync communication we have a community slack with a #containerd channel that everyone is welcome to join and chat about development.
|
For sync communication we have a community slack with a #containerd channel that everyone is welcome to join and chat about development.
|
||||||
|
|
||||||
**Slack:** https://dockr.ly/community
|
**Slack:** https://join.slack.com/t/dockercommunity/shared_invite/enQtNDM4NjAwNDMyOTUwLWZlMDZmYWRjZjk4Zjc5ZGQ5NWZkOWI1Yjk2NGE3ZWVlYjYxM2VhYjczOWIyZDFhZTE3NTUwZWQzMjhmNGYyZTg
|
||||||
|
|
||||||
### Reporting security issues
|
### Reporting security issues
|
||||||
|
|
||||||
|
|
|
@ -315,8 +315,14 @@ func WithImageConfigArgs(image Image, args []string) SpecOpts {
|
||||||
}
|
}
|
||||||
s.Process.Cwd = cwd
|
s.Process.Cwd = cwd
|
||||||
if config.User != "" {
|
if config.User != "" {
|
||||||
return WithUser(config.User)(ctx, client, c, s)
|
if err := WithUser(config.User)(ctx, client, c, s); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return WithAdditionalGIDs(fmt.Sprintf("%d", s.Process.User.UID))(ctx, client, c, s)
|
||||||
|
}
|
||||||
|
// we should query the image's /etc/group for additional GIDs
|
||||||
|
// even if there is no specified user in the image config
|
||||||
|
return WithAdditionalGIDs("root")(ctx, client, c, s)
|
||||||
} else if s.Windows != nil {
|
} else if s.Windows != nil {
|
||||||
s.Process.Env = config.Env
|
s.Process.Env = config.Env
|
||||||
s.Process.Args = append(config.Entrypoint, config.Cmd...)
|
s.Process.Args = append(config.Entrypoint, config.Cmd...)
|
||||||
|
@ -478,12 +484,13 @@ func WithUser(userstr string) SpecOpts {
|
||||||
}
|
}
|
||||||
f := func(root string) error {
|
f := func(root string) error {
|
||||||
if username != "" {
|
if username != "" {
|
||||||
uid, _, err = getUIDGIDFromPath(root, func(u user.User) bool {
|
user, err := getUserFromPath(root, func(u user.User) bool {
|
||||||
return u.Name == username
|
return u.Name == username
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
uid = uint32(user.Uid)
|
||||||
}
|
}
|
||||||
if groupname != "" {
|
if groupname != "" {
|
||||||
gid, err = getGIDFromPath(root, func(g user.Group) bool {
|
gid, err = getGIDFromPath(root, func(g user.Group) bool {
|
||||||
|
@ -541,7 +548,7 @@ func WithUserID(uid uint32) SpecOpts {
|
||||||
if !isRootfsAbs(s.Root.Path) {
|
if !isRootfsAbs(s.Root.Path) {
|
||||||
return errors.Errorf("rootfs absolute path is required")
|
return errors.Errorf("rootfs absolute path is required")
|
||||||
}
|
}
|
||||||
uuid, ugid, err := getUIDGIDFromPath(s.Root.Path, func(u user.User) bool {
|
user, err := getUserFromPath(s.Root.Path, func(u user.User) bool {
|
||||||
return u.Uid == int(uid)
|
return u.Uid == int(uid)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -551,7 +558,7 @@ func WithUserID(uid uint32) SpecOpts {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Process.User.UID, s.Process.User.GID = uuid, ugid
|
s.Process.User.UID, s.Process.User.GID = uint32(user.Uid), uint32(user.Gid)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -567,7 +574,7 @@ func WithUserID(uid uint32) SpecOpts {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return mount.WithTempMount(ctx, mounts, func(root string) error {
|
return mount.WithTempMount(ctx, mounts, func(root string) error {
|
||||||
uuid, ugid, err := getUIDGIDFromPath(root, func(u user.User) bool {
|
user, err := getUserFromPath(root, func(u user.User) bool {
|
||||||
return u.Uid == int(uid)
|
return u.Uid == int(uid)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -577,7 +584,7 @@ func WithUserID(uid uint32) SpecOpts {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Process.User.UID, s.Process.User.GID = uuid, ugid
|
s.Process.User.UID, s.Process.User.GID = uint32(user.Uid), uint32(user.Gid)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -595,13 +602,13 @@ func WithUsername(username string) SpecOpts {
|
||||||
if !isRootfsAbs(s.Root.Path) {
|
if !isRootfsAbs(s.Root.Path) {
|
||||||
return errors.Errorf("rootfs absolute path is required")
|
return errors.Errorf("rootfs absolute path is required")
|
||||||
}
|
}
|
||||||
uid, gid, err := getUIDGIDFromPath(s.Root.Path, func(u user.User) bool {
|
user, err := getUserFromPath(s.Root.Path, func(u user.User) bool {
|
||||||
return u.Name == username
|
return u.Name == username
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Process.User.UID, s.Process.User.GID = uid, gid
|
s.Process.User.UID, s.Process.User.GID = uint32(user.Uid), uint32(user.Gid)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if c.Snapshotter == "" {
|
if c.Snapshotter == "" {
|
||||||
|
@ -616,13 +623,13 @@ func WithUsername(username string) SpecOpts {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return mount.WithTempMount(ctx, mounts, func(root string) error {
|
return mount.WithTempMount(ctx, mounts, func(root string) error {
|
||||||
uid, gid, err := getUIDGIDFromPath(root, func(u user.User) bool {
|
user, err := getUserFromPath(root, func(u user.User) bool {
|
||||||
return u.Name == username
|
return u.Name == username
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Process.User.UID, s.Process.User.GID = uid, gid
|
s.Process.User.UID, s.Process.User.GID = uint32(user.Uid), uint32(user.Gid)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
} else if s.Windows != nil {
|
} else if s.Windows != nil {
|
||||||
|
@ -636,43 +643,27 @@ func WithUsername(username string) SpecOpts {
|
||||||
|
|
||||||
// WithAdditionalGIDs sets the OCI spec's additionalGids array to any additional groups listed
|
// WithAdditionalGIDs sets the OCI spec's additionalGids array to any additional groups listed
|
||||||
// for a particular user in the /etc/groups file of the image's root filesystem
|
// for a particular user in the /etc/groups file of the image's root filesystem
|
||||||
func WithAdditionalGIDs(username string) SpecOpts {
|
// The passed in user can be either a uid or a username.
|
||||||
|
func WithAdditionalGIDs(userstr string) SpecOpts {
|
||||||
return func(ctx context.Context, client Client, c *containers.Container, s *Spec) (err error) {
|
return func(ctx context.Context, client Client, c *containers.Container, s *Spec) (err error) {
|
||||||
setProcess(s)
|
setProcess(s)
|
||||||
if c.Snapshotter == "" && c.SnapshotKey == "" {
|
setAdditionalGids := func(root string) error {
|
||||||
if !isRootfsAbs(s.Root.Path) {
|
var username string
|
||||||
return errors.Errorf("rootfs absolute path is required")
|
uid, err := strconv.Atoi(userstr)
|
||||||
}
|
if err == nil {
|
||||||
gids, err := getSupplementalGroupsFromPath(s.Root.Path, func(g user.Group) bool {
|
user, err := getUserFromPath(root, func(u user.User) bool {
|
||||||
// we only want supplemental groups
|
return u.Uid == uid
|
||||||
if g.Name == username {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, entry := range g.List {
|
|
||||||
if entry == username {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if os.IsNotExist(err) || err == errNoUsersFound {
|
||||||
}
|
|
||||||
s.Process.User.AdditionalGids = gids
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if c.Snapshotter == "" {
|
|
||||||
return errors.Errorf("no snapshotter set for container")
|
|
||||||
}
|
|
||||||
if c.SnapshotKey == "" {
|
|
||||||
return errors.Errorf("rootfs snapshot not created for container")
|
|
||||||
}
|
|
||||||
snapshotter := client.SnapshotService(c.Snapshotter)
|
|
||||||
mounts, err := snapshotter.Mounts(ctx, c.SnapshotKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return mount.WithTempMount(ctx, mounts, func(root string) error {
|
username = user.Name
|
||||||
|
} else {
|
||||||
|
username = userstr
|
||||||
|
}
|
||||||
gids, err := getSupplementalGroupsFromPath(root, func(g user.Group) bool {
|
gids, err := getSupplementalGroupsFromPath(root, func(g user.Group) bool {
|
||||||
// we only want supplemental groups
|
// we only want supplemental groups
|
||||||
if g.Name == username {
|
if g.Name == username {
|
||||||
|
@ -686,11 +677,32 @@ func WithAdditionalGIDs(username string) SpecOpts {
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Process.User.AdditionalGids = gids
|
s.Process.User.AdditionalGids = gids
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
if c.Snapshotter == "" && c.SnapshotKey == "" {
|
||||||
|
if !isRootfsAbs(s.Root.Path) {
|
||||||
|
return errors.Errorf("rootfs absolute path is required")
|
||||||
|
}
|
||||||
|
return setAdditionalGids(s.Root.Path)
|
||||||
|
}
|
||||||
|
if c.Snapshotter == "" {
|
||||||
|
return errors.Errorf("no snapshotter set for container")
|
||||||
|
}
|
||||||
|
if c.SnapshotKey == "" {
|
||||||
|
return errors.Errorf("rootfs snapshot not created for container")
|
||||||
|
}
|
||||||
|
snapshotter := client.SnapshotService(c.Snapshotter)
|
||||||
|
mounts, err := snapshotter.Mounts(ctx, c.SnapshotKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return mount.WithTempMount(ctx, mounts, setAdditionalGids)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,20 +753,19 @@ func WithAmbientCapabilities(caps []string) SpecOpts {
|
||||||
|
|
||||||
var errNoUsersFound = errors.New("no users found")
|
var errNoUsersFound = errors.New("no users found")
|
||||||
|
|
||||||
func getUIDGIDFromPath(root string, filter func(user.User) bool) (uid, gid uint32, err error) {
|
func getUserFromPath(root string, filter func(user.User) bool) (user.User, error) {
|
||||||
ppath, err := fs.RootPath(root, "/etc/passwd")
|
ppath, err := fs.RootPath(root, "/etc/passwd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return user.User{}, err
|
||||||
}
|
}
|
||||||
users, err := user.ParsePasswdFileFilter(ppath, filter)
|
users, err := user.ParsePasswdFileFilter(ppath, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return user.User{}, err
|
||||||
}
|
}
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
return 0, 0, errNoUsersFound
|
return user.User{}, errNoUsersFound
|
||||||
}
|
}
|
||||||
u := users[0]
|
return users[0], nil
|
||||||
return uint32(u.Uid), uint32(u.Gid), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var errNoGroupsFound = errors.New("no groups found")
|
var errNoGroupsFound = errors.New("no groups found")
|
||||||
|
|
|
@ -607,9 +607,12 @@ func writeContent(ctx context.Context, store content.Ingester, mediaType, ref st
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writer.Commit(ctx, size, "", opts...); err != nil {
|
if err := writer.Commit(ctx, size, "", opts...); err != nil {
|
||||||
|
if !errdefs.IsAlreadyExists(err) {
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return v1.Descriptor{
|
return v1.Descriptor{
|
||||||
MediaType: mediaType,
|
MediaType: mediaType,
|
||||||
Digest: writer.Digest(),
|
Digest: writer.Digest(),
|
||||||
|
|
|
@ -19,7 +19,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.0
|
||||||
github.com/gogo/protobuf v1.0.0
|
github.com/gogo/protobuf v1.0.0
|
||||||
github.com/gogo/googleapis 08a7655d27152912db7aaf4f983275eaf8d128ef
|
github.com/gogo/googleapis 08a7655d27152912db7aaf4f983275eaf8d128ef
|
||||||
github.com/golang/protobuf v1.1.0
|
github.com/golang/protobuf v1.1.0
|
||||||
github.com/opencontainers/runtime-spec d810dbc60d8c5aeeb3d054bd1132fab2121968ce # v1.0.1-43-gd810dbc
|
github.com/opencontainers/runtime-spec eba862dc2470385a233c7507392675cbeadf7353 # v1.0.1-45-geba862d
|
||||||
github.com/opencontainers/runc 20aff4f0488c6d4b8df4d85b4f63f1f704c11abd
|
github.com/opencontainers/runc 20aff4f0488c6d4b8df4d85b4f63f1f704c11abd
|
||||||
github.com/sirupsen/logrus v1.0.0
|
github.com/sirupsen/logrus v1.0.0
|
||||||
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
|
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
|
||||||
|
@ -34,17 +34,17 @@ github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
|
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
|
||||||
github.com/Microsoft/go-winio v0.4.10
|
github.com/Microsoft/go-winio v0.4.10
|
||||||
github.com/Microsoft/hcsshim 44c060121b68e8bdc40b411beba551f3b4ee9e55
|
github.com/Microsoft/hcsshim 44c060121b68e8bdc40b411beba551f3b4ee9e55
|
||||||
github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd
|
|
||||||
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
|
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
|
||||||
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4
|
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4
|
||||||
github.com/containerd/ttrpc 94dde388801693c54f88a6596f713b51a8b30b2d
|
github.com/containerd/ttrpc 94dde388801693c54f88a6596f713b51a8b30b2d
|
||||||
github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
|
github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
|
||||||
gotest.tools v2.1.0
|
gotest.tools v2.1.0
|
||||||
github.com/google/go-cmp v0.1.0
|
github.com/google/go-cmp v0.1.0
|
||||||
|
go.etcd.io/bbolt v1.3.1-etcd.8
|
||||||
|
|
||||||
# cri dependencies
|
# cri dependencies
|
||||||
github.com/containerd/cri v1.11.1
|
github.com/containerd/cri 9f39e3289533fc228c5e5fcac0a6dbdd60c6047b # release/1.2 branch
|
||||||
github.com/containerd/go-cni 5882530828ecf62032409b298a3e8b19e08b6534
|
github.com/containerd/go-cni 6d7b509a054a3cb1c35ed1865d4fde2f0cb547cd
|
||||||
github.com/blang/semver v3.1.0
|
github.com/blang/semver v3.1.0
|
||||||
github.com/containernetworking/cni v0.6.0
|
github.com/containernetworking/cni v0.6.0
|
||||||
github.com/containernetworking/plugins v0.7.0
|
github.com/containernetworking/plugins v0.7.0
|
||||||
|
@ -52,32 +52,33 @@ github.com/davecgh/go-spew v1.1.0
|
||||||
github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621
|
github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621
|
||||||
github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00
|
github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00
|
||||||
github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528
|
github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528
|
||||||
github.com/emicklei/go-restful ff4f55a206334ef123e4f79bbf348980da81ca46
|
github.com/emicklei/go-restful v2.2.1
|
||||||
github.com/ghodss/yaml 73d445a93680fa1a78ae23a5839bad48f32ba1ee
|
github.com/ghodss/yaml v1.0.0
|
||||||
github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed
|
github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed
|
||||||
github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c
|
github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c
|
||||||
github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55
|
github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55
|
||||||
github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f
|
github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f
|
||||||
github.com/json-iterator/go f2b4162afba35581b6d4a50d3b8f34e33c144682
|
github.com/json-iterator/go 1.1.5
|
||||||
github.com/modern-go/reflect2 05fbef0ca5da472bbf96c9322b84a53edc03c9fd
|
github.com/modern-go/reflect2 1.0.1
|
||||||
github.com/modern-go/concurrent 1.0.3
|
github.com/modern-go/concurrent 1.0.3
|
||||||
github.com/opencontainers/runtime-tools v0.6.0
|
github.com/opencontainers/runtime-tools v0.6.0
|
||||||
github.com/opencontainers/selinux 4a2974bf1ee960774ffd517717f1f45325af0206
|
github.com/opencontainers/selinux b6fa367ed7f534f9ba25391cc2d467085dbb445a
|
||||||
github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
|
github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
|
||||||
github.com/tchap/go-patricia 5ad6cdb7538b0097d5598c7e57f0a24072adf7dc
|
github.com/tchap/go-patricia v2.2.6
|
||||||
github.com/xeipuuv/gojsonpointer 4e3ac2762d5f479393488629ee9370b50873b3a6
|
github.com/xeipuuv/gojsonpointer 4e3ac2762d5f479393488629ee9370b50873b3a6
|
||||||
github.com/xeipuuv/gojsonreference bd5ef7bd5415a7ac448318e64f11a24cd21e594b
|
github.com/xeipuuv/gojsonreference bd5ef7bd5415a7ac448318e64f11a24cd21e594b
|
||||||
github.com/xeipuuv/gojsonschema 1d523034197ff1f222f6429836dd36a2457a1874
|
github.com/xeipuuv/gojsonschema 1d523034197ff1f222f6429836dd36a2457a1874
|
||||||
golang.org/x/crypto 49796115aa4b964c318aad4f3084fdb41e9aa067
|
golang.org/x/crypto 49796115aa4b964c318aad4f3084fdb41e9aa067
|
||||||
|
golang.org/x/oauth2 a6bd8cefa1811bd24b86f8902872e4e8225f74c4
|
||||||
golang.org/x/time f51c12702a4d776e4c1fa9b0fabab841babae631
|
golang.org/x/time f51c12702a4d776e4c1fa9b0fabab841babae631
|
||||||
gopkg.in/inf.v0 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
|
gopkg.in/inf.v0 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
|
||||||
gopkg.in/yaml.v2 v2.2.1
|
gopkg.in/yaml.v2 v2.2.1
|
||||||
k8s.io/api 9e5ffd1f1320950b238cfce291b926411f0af722
|
k8s.io/api 012f271b5d41baad56190c5f1ae19bff16df0fd8
|
||||||
k8s.io/apimachinery ed135c5b96450fd24e5e981c708114fbbd950697
|
k8s.io/apimachinery 6429050ef506887d121f3e7306e894f8900d8a63
|
||||||
k8s.io/apiserver a90e3a95c2e91b944bfca8225c4e0d12e42a9eb5
|
k8s.io/apiserver e9312c15296b6c2c923ebd5031ff5d1d5fd022d7
|
||||||
k8s.io/client-go 03bfb9bdcfe5482795b999f39ca3ed9ad42ce5bb
|
k8s.io/client-go 37c3c02ec96533daec0dbda1f39a6b1d68505c79
|
||||||
k8s.io/kubernetes v1.11.0
|
k8s.io/kubernetes v1.12.0-beta.1
|
||||||
k8s.io/utils 733eca437aa39379e4bcc25e726439dfca40fcff
|
k8s.io/utils 982821ea41da7e7c15f3d3738921eb2e7e241ccd
|
||||||
|
|
||||||
# zfs dependencies
|
# zfs dependencies
|
||||||
github.com/containerd/zfs 9a0b8b8b5982014b729cd34eb7cd7a11062aa6ec
|
github.com/containerd/zfs 9a0b8b8b5982014b729cd34eb7cd7a11062aa6ec
|
||||||
|
|
|
@ -72,7 +72,7 @@ func copyDirectory(dst, src string, inodes map[uint64]string) error {
|
||||||
if err := os.Link(link, target); err != nil {
|
if err := os.Link(link, target); err != nil {
|
||||||
return errors.Wrap(err, "failed to create hard link")
|
return errors.Wrap(err, "failed to create hard link")
|
||||||
}
|
}
|
||||||
} else if err := copyFile(source, target); err != nil {
|
} else if err := CopyFile(target, source); err != nil {
|
||||||
return errors.Wrap(err, "failed to copy files")
|
return errors.Wrap(err, "failed to copy files")
|
||||||
}
|
}
|
||||||
case (fi.Mode() & os.ModeSymlink) == os.ModeSymlink:
|
case (fi.Mode() & os.ModeSymlink) == os.ModeSymlink:
|
||||||
|
@ -103,7 +103,9 @@ func copyDirectory(dst, src string, inodes map[uint64]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyFile(source, target string) error {
|
// CopyFile copies the source file to the target.
|
||||||
|
// The most efficient means of copying is used for the platform.
|
||||||
|
func CopyFile(target, source string) error {
|
||||||
src, err := os.Open(source)
|
src, err := os.Open(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to open source %s", source)
|
return errors.Wrapf(err, "failed to open source %s", source)
|
||||||
|
|
|
@ -49,20 +49,26 @@ func copyFileContent(dst, src *os.File) error {
|
||||||
return errors.Wrap(err, "unable to stat source")
|
return errors.Wrap(err, "unable to stat source")
|
||||||
}
|
}
|
||||||
|
|
||||||
n, err := unix.CopyFileRange(int(src.Fd()), nil, int(dst.Fd()), nil, int(st.Size()), 0)
|
size := st.Size()
|
||||||
|
first := true
|
||||||
|
srcFd := int(src.Fd())
|
||||||
|
dstFd := int(dst.Fd())
|
||||||
|
|
||||||
|
for size > 0 {
|
||||||
|
n, err := unix.CopyFileRange(srcFd, nil, dstFd, nil, int(size), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != unix.ENOSYS && err != unix.EXDEV {
|
if (err != unix.ENOSYS && err != unix.EXDEV) || !first {
|
||||||
return errors.Wrap(err, "copy file range failed")
|
return errors.Wrap(err, "copy file range failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := bufferPool.Get().(*[]byte)
|
buf := bufferPool.Get().(*[]byte)
|
||||||
_, err = io.CopyBuffer(dst, src, *buf)
|
_, err = io.CopyBuffer(dst, src, *buf)
|
||||||
bufferPool.Put(buf)
|
bufferPool.Put(buf)
|
||||||
return err
|
return errors.Wrap(err, "userspace copy failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(n) != st.Size() {
|
first = false
|
||||||
return errors.Wrapf(err, "short copy: %d of %d", int64(n), st.Size())
|
size -= int64(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,8 +10,8 @@ type Usage struct {
|
||||||
|
|
||||||
// DiskUsage counts the number of inodes and disk usage for the resources under
|
// DiskUsage counts the number of inodes and disk usage for the resources under
|
||||||
// path.
|
// path.
|
||||||
func DiskUsage(roots ...string) (Usage, error) {
|
func DiskUsage(ctx context.Context, roots ...string) (Usage, error) {
|
||||||
return diskUsage(roots...)
|
return diskUsage(ctx, roots...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffUsage counts the numbers of inodes and disk usage in the
|
// DiffUsage counts the numbers of inodes and disk usage in the
|
||||||
|
|
|
@ -24,7 +24,7 @@ func newInode(stat *syscall.Stat_t) inode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func diskUsage(roots ...string) (Usage, error) {
|
func diskUsage(ctx context.Context, roots ...string) (Usage, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
size int64
|
size int64
|
||||||
|
@ -37,6 +37,12 @@ func diskUsage(roots ...string) (Usage, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
inoKey := newInode(fi.Sys().(*syscall.Stat_t))
|
inoKey := newInode(fi.Sys().(*syscall.Stat_t))
|
||||||
if _, ok := inodes[inoKey]; !ok {
|
if _, ok := inodes[inoKey]; !ok {
|
||||||
inodes[inoKey] = struct{}{}
|
inodes[inoKey] = struct{}{}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func diskUsage(roots ...string) (Usage, error) {
|
func diskUsage(ctx context.Context, roots ...string) (Usage, error) {
|
||||||
var (
|
var (
|
||||||
size int64
|
size int64
|
||||||
)
|
)
|
||||||
|
@ -21,6 +21,12 @@ func diskUsage(roots ...string) (Usage, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
size += fi.Size()
|
size += fi.Size()
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package syscallx
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
// Readlink returns the destination of the named symbolic link.
|
||||||
|
func Readlink(path string, buf []byte) (n int, err error) {
|
||||||
|
return syscall.Readlink(path, buf)
|
||||||
|
}
|
96
vendor/github.com/containerd/continuity/syscallx/syscall_windows.go
generated
vendored
Normal file
96
vendor/github.com/containerd/continuity/syscallx/syscall_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
package syscallx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type reparseDataBuffer struct {
|
||||||
|
ReparseTag uint32
|
||||||
|
ReparseDataLength uint16
|
||||||
|
Reserved uint16
|
||||||
|
|
||||||
|
// GenericReparseBuffer
|
||||||
|
reparseBuffer byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type mountPointReparseBuffer struct {
|
||||||
|
SubstituteNameOffset uint16
|
||||||
|
SubstituteNameLength uint16
|
||||||
|
PrintNameOffset uint16
|
||||||
|
PrintNameLength uint16
|
||||||
|
PathBuffer [1]uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
type symbolicLinkReparseBuffer struct {
|
||||||
|
SubstituteNameOffset uint16
|
||||||
|
SubstituteNameLength uint16
|
||||||
|
PrintNameOffset uint16
|
||||||
|
PrintNameLength uint16
|
||||||
|
Flags uint32
|
||||||
|
PathBuffer [1]uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
_IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
|
||||||
|
_SYMLINK_FLAG_RELATIVE = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Readlink returns the destination of the named symbolic link.
|
||||||
|
func Readlink(path string, buf []byte) (n int, err error) {
|
||||||
|
fd, err := syscall.CreateFile(syscall.StringToUTF16Ptr(path), syscall.GENERIC_READ, 0, nil, syscall.OPEN_EXISTING,
|
||||||
|
syscall.FILE_FLAG_OPEN_REPARSE_POINT|syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
defer syscall.CloseHandle(fd)
|
||||||
|
|
||||||
|
rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
|
||||||
|
var bytesReturned uint32
|
||||||
|
err = syscall.DeviceIoControl(fd, syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rdb := (*reparseDataBuffer)(unsafe.Pointer(&rdbbuf[0]))
|
||||||
|
var s string
|
||||||
|
switch rdb.ReparseTag {
|
||||||
|
case syscall.IO_REPARSE_TAG_SYMLINK:
|
||||||
|
data := (*symbolicLinkReparseBuffer)(unsafe.Pointer(&rdb.reparseBuffer))
|
||||||
|
p := (*[0xffff]uint16)(unsafe.Pointer(&data.PathBuffer[0]))
|
||||||
|
s = syscall.UTF16ToString(p[data.SubstituteNameOffset/2 : (data.SubstituteNameOffset+data.SubstituteNameLength)/2])
|
||||||
|
if data.Flags&_SYMLINK_FLAG_RELATIVE == 0 {
|
||||||
|
if len(s) >= 4 && s[:4] == `\??\` {
|
||||||
|
s = s[4:]
|
||||||
|
switch {
|
||||||
|
case len(s) >= 2 && s[1] == ':': // \??\C:\foo\bar
|
||||||
|
// do nothing
|
||||||
|
case len(s) >= 4 && s[:4] == `UNC\`: // \??\UNC\foo\bar
|
||||||
|
s = `\\` + s[4:]
|
||||||
|
default:
|
||||||
|
// unexpected; do nothing
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// unexpected; do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _IO_REPARSE_TAG_MOUNT_POINT:
|
||||||
|
data := (*mountPointReparseBuffer)(unsafe.Pointer(&rdb.reparseBuffer))
|
||||||
|
p := (*[0xffff]uint16)(unsafe.Pointer(&data.PathBuffer[0]))
|
||||||
|
s = syscall.UTF16ToString(p[data.SubstituteNameOffset/2 : (data.SubstituteNameOffset+data.SubstituteNameLength)/2])
|
||||||
|
if len(s) >= 4 && s[:4] == `\??\` { // \??\C:\foo\bar
|
||||||
|
if len(s) < 48 || s[:11] != `\??\Volume{` {
|
||||||
|
s = s[4:]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// unexpected; do nothing
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// the path is not a symlink or junction but another type of reparse
|
||||||
|
// point
|
||||||
|
return -1, syscall.ENOENT
|
||||||
|
}
|
||||||
|
n = copy(buf, []byte(s))
|
||||||
|
|
||||||
|
return n, nil
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
This package is for internal use only. It is intended to only have
|
||||||
|
temporary changes before they are upstreamed to golang.org/x/sys/
|
||||||
|
(a.k.a. https://github.com/golang/sys).
|
|
@ -1,10 +0,0 @@
|
||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !gccgo
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
TEXT ·use(SB),NOSPLIT,$0
|
|
||||||
RET
|
|
|
@ -1,18 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
const (
|
|
||||||
// AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in <sys/fcntl.h>
|
|
||||||
AtSymlinkNofollow = 0x20
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
|
|
||||||
// SYS_FCHMODAT defined from golang.org/sys/unix
|
|
||||||
SYS_FCHMODAT = 467
|
|
||||||
)
|
|
||||||
|
|
||||||
// These functions will be generated by generate.sh
|
|
||||||
// $ GOOS=darwin GOARCH=386 ./generate.sh chmod
|
|
||||||
// $ GOOS=darwin GOARCH=amd64 ./generate.sh chmod
|
|
||||||
|
|
||||||
//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
|
|
|
@ -1,25 +0,0 @@
|
||||||
// mksyscall.pl -l32 chmod_darwin.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
// mksyscall.pl chmod_darwin.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
const (
|
|
||||||
// AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in <sys/fcntl.h>
|
|
||||||
AtSymlinkNofollow = 0x200
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
|
|
||||||
// SYS_FCHMODAT defined from golang.org/sys/unix
|
|
||||||
SYS_FCHMODAT = 490
|
|
||||||
)
|
|
||||||
|
|
||||||
// These functions will be generated by generate.sh
|
|
||||||
// $ GOOS=freebsd GOARCH=amd64 ./generate.sh chmod
|
|
||||||
|
|
||||||
//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
|
|
|
@ -1,25 +0,0 @@
|
||||||
// mksyscall.pl chmod_freebsd.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const (
|
|
||||||
// AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in /usr/include/linux/fcntl.h
|
|
||||||
AtSymlinkNofollow = 0x100
|
|
||||||
)
|
|
||||||
|
|
||||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) error {
|
|
||||||
return syscall.Fchmodat(dirfd, path, mode, flags)
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
const (
|
|
||||||
AtSymlinkNofollow = unix.AT_SYMLINK_NOFOLLOW
|
|
||||||
)
|
|
||||||
|
|
||||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) error {
|
|
||||||
return unix.Fchmodat(dirfd, path, mode, flags)
|
|
||||||
}
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
package sysx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/containerd/continuity/syscallx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Readlink returns the destination of the named symbolic link.
|
||||||
|
// If there is an error, it will be of type *PathError.
|
||||||
|
func Readlink(name string) (string, error) {
|
||||||
|
for len := 128; ; len *= 2 {
|
||||||
|
b := make([]byte, len)
|
||||||
|
n, e := fixCount(syscallx.Readlink(fixLongPath(name), b))
|
||||||
|
if e != nil {
|
||||||
|
return "", &os.PathError{Op: "readlink", Path: name, Err: e}
|
||||||
|
}
|
||||||
|
if n < len {
|
||||||
|
return string(b[0:n]), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Many functions in package syscall return a count of -1 instead of 0.
|
||||||
|
// Using fixCount(call()) instead of call() corrects the count.
|
||||||
|
func fixCount(n int, err error) (int, error) {
|
||||||
|
if n < 0 {
|
||||||
|
n = 0
|
||||||
|
}
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// fixLongPath returns the extended-length (\\?\-prefixed) form of
|
||||||
|
// path when needed, in order to avoid the default 260 character file
|
||||||
|
// path limit imposed by Windows. If path is not easily converted to
|
||||||
|
// the extended-length form (for example, if path is a relative path
|
||||||
|
// or contains .. elements), or is short enough, fixLongPath returns
|
||||||
|
// path unmodified.
|
||||||
|
//
|
||||||
|
// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath
|
||||||
|
func fixLongPath(path string) string {
|
||||||
|
// Do nothing (and don't allocate) if the path is "short".
|
||||||
|
// Empirically (at least on the Windows Server 2013 builder),
|
||||||
|
// the kernel is arbitrarily okay with < 248 bytes. That
|
||||||
|
// matches what the docs above say:
|
||||||
|
// "When using an API to create a directory, the specified
|
||||||
|
// path cannot be so long that you cannot append an 8.3 file
|
||||||
|
// name (that is, the directory name cannot exceed MAX_PATH
|
||||||
|
// minus 12)." Since MAX_PATH is 260, 260 - 12 = 248.
|
||||||
|
//
|
||||||
|
// The MSDN docs appear to say that a normal path that is 248 bytes long
|
||||||
|
// will work; empirically the path must be less then 248 bytes long.
|
||||||
|
if len(path) < 248 {
|
||||||
|
// Don't fix. (This is how Go 1.7 and earlier worked,
|
||||||
|
// not automatically generating the \\?\ form)
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
// The extended form begins with \\?\, as in
|
||||||
|
// \\?\c:\windows\foo.txt or \\?\UNC\server\share\foo.txt.
|
||||||
|
// The extended form disables evaluation of . and .. path
|
||||||
|
// elements and disables the interpretation of / as equivalent
|
||||||
|
// to \. The conversion here rewrites / to \ and elides
|
||||||
|
// . elements as well as trailing or duplicate separators. For
|
||||||
|
// simplicity it avoids the conversion entirely for relative
|
||||||
|
// paths or paths containing .. elements. For now,
|
||||||
|
// \\server\share paths are not converted to
|
||||||
|
// \\?\UNC\server\share paths because the rules for doing so
|
||||||
|
// are less well-specified.
|
||||||
|
if len(path) >= 2 && path[:2] == `\\` {
|
||||||
|
// Don't canonicalize UNC paths.
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
// Relative path
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
const prefix = `\\?`
|
||||||
|
|
||||||
|
pathbuf := make([]byte, len(prefix)+len(path)+len(`\`))
|
||||||
|
copy(pathbuf, prefix)
|
||||||
|
n := len(path)
|
||||||
|
r, w := 0, len(prefix)
|
||||||
|
for r < n {
|
||||||
|
switch {
|
||||||
|
case os.IsPathSeparator(path[r]):
|
||||||
|
// empty block
|
||||||
|
r++
|
||||||
|
case path[r] == '.' && (r+1 == n || os.IsPathSeparator(path[r+1])):
|
||||||
|
// /./
|
||||||
|
r++
|
||||||
|
case r+1 < n && path[r] == '.' && path[r+1] == '.' && (r+2 == n || os.IsPathSeparator(path[r+2])):
|
||||||
|
// /../ is currently unhandled
|
||||||
|
return path
|
||||||
|
default:
|
||||||
|
pathbuf[w] = '\\'
|
||||||
|
w++
|
||||||
|
for ; r < n && !os.IsPathSeparator(path[r]); r++ {
|
||||||
|
pathbuf[w] = path[r]
|
||||||
|
w++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A drive's root directory needs a trailing \
|
||||||
|
if w == len(`\\?\c:`) {
|
||||||
|
pathbuf[w] = '\\'
|
||||||
|
w++
|
||||||
|
}
|
||||||
|
return string(pathbuf[:w])
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _zero uintptr
|
|
||||||
|
|
||||||
// use is a no-op, but the compiler cannot see that it is.
|
|
||||||
// Calling use(p) ensures that p is kept live until that point.
|
|
||||||
//go:noescape
|
|
||||||
func use(p unsafe.Pointer)
|
|
||||||
|
|
||||||
// Do the interface allocations only once for common
|
|
||||||
// Errno values.
|
|
||||||
var (
|
|
||||||
errEAGAIN error = syscall.EAGAIN
|
|
||||||
errEINVAL error = syscall.EINVAL
|
|
||||||
errENOENT error = syscall.ENOENT
|
|
||||||
)
|
|
||||||
|
|
||||||
// errnoErr returns common boxed Errno values, to prevent
|
|
||||||
// allocations at runtime.
|
|
||||||
func errnoErr(e syscall.Errno) error {
|
|
||||||
switch e {
|
|
||||||
case 0:
|
|
||||||
return nil
|
|
||||||
case syscall.EAGAIN:
|
|
||||||
return errEAGAIN
|
|
||||||
case syscall.EINVAL:
|
|
||||||
return errEINVAL
|
|
||||||
case syscall.ENOENT:
|
|
||||||
return errENOENT
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
}
|
|
|
@ -1,14 +1,56 @@
|
||||||
|
// +build linux darwin
|
||||||
|
|
||||||
package sysx
|
package sysx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultXattrBufferSize = 5
|
// Listxattr calls syscall listxattr and reads all content
|
||||||
|
// and returns a string array
|
||||||
|
func Listxattr(path string) ([]string, error) {
|
||||||
|
return listxattrAll(path, unix.Listxattr)
|
||||||
|
}
|
||||||
|
|
||||||
var ErrNotSupported = fmt.Errorf("not supported")
|
// Removexattr calls syscall removexattr
|
||||||
|
func Removexattr(path string, attr string) (err error) {
|
||||||
|
return unix.Removexattr(path, attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setxattr calls syscall setxattr
|
||||||
|
func Setxattr(path string, attr string, data []byte, flags int) (err error) {
|
||||||
|
return unix.Setxattr(path, attr, data, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getxattr calls syscall getxattr
|
||||||
|
func Getxattr(path, attr string) ([]byte, error) {
|
||||||
|
return getxattrAll(path, attr, unix.Getxattr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LListxattr lists xattrs, not following symlinks
|
||||||
|
func LListxattr(path string) ([]string, error) {
|
||||||
|
return listxattrAll(path, unix.Llistxattr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LRemovexattr removes an xattr, not following symlinks
|
||||||
|
func LRemovexattr(path string, attr string) (err error) {
|
||||||
|
return unix.Lremovexattr(path, attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LSetxattr sets an xattr, not following symlinks
|
||||||
|
func LSetxattr(path string, attr string, data []byte, flags int) (err error) {
|
||||||
|
return unix.Lsetxattr(path, attr, data, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LGetxattr gets an xattr, not following symlinks
|
||||||
|
func LGetxattr(path, attr string) ([]byte, error) {
|
||||||
|
return getxattrAll(path, attr, unix.Lgetxattr)
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultXattrBufferSize = 5
|
||||||
|
|
||||||
type listxattrFunc func(path string, dest []byte) (int, error)
|
type listxattrFunc func(path string, dest []byte) (int, error)
|
||||||
|
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
// These functions will be generated by generate.sh
|
|
||||||
// $ GOOS=darwin GOARCH=386 ./generate.sh xattr
|
|
||||||
// $ GOOS=darwin GOARCH=amd64 ./generate.sh xattr
|
|
||||||
|
|
||||||
//sys getxattr(path string, attr string, dest []byte, pos int, options int) (sz int, err error)
|
|
||||||
//sys setxattr(path string, attr string, data []byte, flags int) (err error)
|
|
||||||
//sys removexattr(path string, attr string, options int) (err error)
|
|
||||||
//sys listxattr(path string, dest []byte, options int) (sz int, err error)
|
|
||||||
//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
|
|
||||||
|
|
||||||
const (
|
|
||||||
xattrNoFollow = 0x01
|
|
||||||
)
|
|
||||||
|
|
||||||
func listxattrFollow(path string, dest []byte) (sz int, err error) {
|
|
||||||
return listxattr(path, dest, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listxattr calls syscall getxattr
|
|
||||||
func Listxattr(path string) ([]string, error) {
|
|
||||||
return listxattrAll(path, listxattrFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removexattr calls syscall getxattr
|
|
||||||
func Removexattr(path string, attr string) (err error) {
|
|
||||||
return removexattr(path, attr, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setxattr calls syscall setxattr
|
|
||||||
func Setxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
return setxattr(path, attr, data, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getxattrFollow(path, attr string, dest []byte) (sz int, err error) {
|
|
||||||
return getxattr(path, attr, dest, 0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getxattr calls syscall getxattr
|
|
||||||
func Getxattr(path, attr string) ([]byte, error) {
|
|
||||||
return getxattrAll(path, attr, getxattrFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
func listxattrNoFollow(path string, dest []byte) (sz int, err error) {
|
|
||||||
return listxattr(path, dest, xattrNoFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LListxattr calls syscall listxattr with XATTR_NOFOLLOW
|
|
||||||
func LListxattr(path string) ([]string, error) {
|
|
||||||
return listxattrAll(path, listxattrNoFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LRemovexattr calls syscall removexattr with XATTR_NOFOLLOW
|
|
||||||
func LRemovexattr(path string, attr string) (err error) {
|
|
||||||
return removexattr(path, attr, xattrNoFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setxattr calls syscall setxattr with XATTR_NOFOLLOW
|
|
||||||
func LSetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
return setxattr(path, attr, data, flags|xattrNoFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getxattrNoFollow(path, attr string, dest []byte) (sz int, err error) {
|
|
||||||
return getxattr(path, attr, dest, 0, xattrNoFollow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LGetxattr calls syscall getxattr with XATTR_NOFOLLOW
|
|
||||||
func LGetxattr(path, attr string) ([]byte, error) {
|
|
||||||
return getxattrAll(path, attr, getxattrNoFollow)
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl -l32 xattr_darwin.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func getxattr(path string, attr string, dest []byte, pos int, options int) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), uintptr(pos), uintptr(options))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func setxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func removexattr(path string, attr string, options int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(options))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func listxattr(path string, dest []byte, options int) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)), uintptr(options), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_darwin.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func getxattr(path string, attr string, dest []byte, pos int, options int) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), uintptr(pos), uintptr(options))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func setxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func removexattr(path string, attr string, options int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(options))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func listxattr(path string, dest []byte, options int) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)), uintptr(options), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Initial stub version for FreeBSD. FreeBSD has a different
|
|
||||||
// syscall API from Darwin and Linux for extended attributes;
|
|
||||||
// it is also not widely used. It is not exposed at all by the
|
|
||||||
// Go syscall package, so we need to implement directly eventually.
|
|
||||||
|
|
||||||
var unsupported = errors.New("extended attributes unsupported on FreeBSD")
|
|
|
@ -1,61 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// These functions will be generated by generate.sh
|
|
||||||
// $ GOOS=linux GOARCH=386 ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=amd64 ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=arm ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=arm64 ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=ppc64 ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=ppc64le ./generate.sh xattr
|
|
||||||
// $ GOOS=linux GOARCH=s390x ./generate.sh xattr
|
|
||||||
|
|
||||||
// Listxattr calls syscall listxattr and reads all content
|
|
||||||
// and returns a string array
|
|
||||||
func Listxattr(path string) ([]string, error) {
|
|
||||||
return listxattrAll(path, syscall.Listxattr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removexattr calls syscall removexattr
|
|
||||||
func Removexattr(path string, attr string) (err error) {
|
|
||||||
return syscall.Removexattr(path, attr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setxattr calls syscall setxattr
|
|
||||||
func Setxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
return syscall.Setxattr(path, attr, data, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getxattr calls syscall getxattr
|
|
||||||
func Getxattr(path, attr string) ([]byte, error) {
|
|
||||||
return getxattrAll(path, attr, syscall.Getxattr)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys llistxattr(path string, dest []byte) (sz int, err error)
|
|
||||||
|
|
||||||
// LListxattr lists xattrs, not following symlinks
|
|
||||||
func LListxattr(path string) ([]string, error) {
|
|
||||||
return listxattrAll(path, llistxattr)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys lremovexattr(path string, attr string) (err error)
|
|
||||||
|
|
||||||
// LRemovexattr removes an xattr, not following symlinks
|
|
||||||
func LRemovexattr(path string, attr string) (err error) {
|
|
||||||
return lremovexattr(path, attr)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys lsetxattr(path string, attr string, data []byte, flags int) (err error)
|
|
||||||
|
|
||||||
// LSetxattr sets an xattr, not following symlinks
|
|
||||||
func LSetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
return lsetxattr(path, attr, data, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys lgetxattr(path string, attr string, dest []byte) (sz int, err error)
|
|
||||||
|
|
||||||
// LGetxattr gets an xattr, not following symlinks
|
|
||||||
func LGetxattr(path, attr string) ([]byte, error) {
|
|
||||||
return getxattrAll(path, attr, lgetxattr)
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl -l32 xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl -l32 xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
// mksyscall.pl xattr_linux.go
|
|
||||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
||||||
|
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func llistxattr(path string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall(syscall.SYS_LLISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lremovexattr(path string, attr string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall(syscall.SYS_LREMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lsetxattr(path string, attr string, data []byte, flags int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(data) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&data[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
_, _, e1 := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func lgetxattr(path string, attr string, dest []byte) (sz int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = syscall.BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = syscall.BytePtrFromString(attr)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p2 unsafe.Pointer
|
|
||||||
if len(dest) > 0 {
|
|
||||||
_p2 = unsafe.Pointer(&dest[0])
|
|
||||||
} else {
|
|
||||||
_p2 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
sz = int(r0)
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
var unsupported = errors.New("extended attributes unsupported on OpenBSD")
|
|
|
@ -1,12 +0,0 @@
|
||||||
package sysx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Initial stub version for Solaris. Solaris has a different
|
|
||||||
// syscall API from Darwin and Linux for extended attributes;
|
|
||||||
// it is also not widely used. It is not exposed at all by the
|
|
||||||
// Go syscall package, so we need to implement directly eventually.
|
|
||||||
|
|
||||||
var unsupported = errors.New("extended attributes unsupported on Solaris")
|
|
|
@ -1,7 +1,14 @@
|
||||||
// +build freebsd openbsd solaris
|
// +build !linux,!darwin
|
||||||
|
|
||||||
package sysx
|
package sysx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var unsupported = errors.New("extended attributes unsupported on " + runtime.GOOS)
|
||||||
|
|
||||||
// Listxattr calls syscall listxattr and reads all content
|
// Listxattr calls syscall listxattr and reads all content
|
||||||
// and returns a string array
|
// and returns a string array
|
||||||
func Listxattr(path string) ([]string, error) {
|
func Listxattr(path string) ([]string, error) {
|
||||||
|
|
|
@ -10,4 +10,4 @@ github.com/spf13/pflag 4c012f6dcd9546820e378d0bdda4d8fc772cdfea
|
||||||
golang.org/x/crypto 9f005a07e0d31d45e6656d241bb5c0f2efd4bc94
|
golang.org/x/crypto 9f005a07e0d31d45e6656d241bb5c0f2efd4bc94
|
||||||
golang.org/x/net a337091b0525af65de94df2eb7e98bd9962dcbe2
|
golang.org/x/net a337091b0525af65de94df2eb7e98bd9962dcbe2
|
||||||
golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
|
golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c
|
||||||
golang.org/x/sys 665f6529cca930e27b831a0d1dafffbe1c172924
|
golang.org/x/sys 77b0e4315053a57ed2962443614bdb28db152054
|
||||||
|
|
|
@ -81,10 +81,12 @@ func (adapter *Decoder) More() bool {
|
||||||
if iter.Error != nil {
|
if iter.Error != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if iter.head != iter.tail {
|
c := iter.nextToken()
|
||||||
return true
|
if c == 0 {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return iter.loadMore()
|
iter.unreadByte()
|
||||||
|
return c != ']' && c != '}'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffered remaining buffer
|
// Buffered remaining buffer
|
||||||
|
@ -98,7 +100,7 @@ func (adapter *Decoder) Buffered() io.Reader {
|
||||||
func (adapter *Decoder) UseNumber() {
|
func (adapter *Decoder) UseNumber() {
|
||||||
cfg := adapter.iter.cfg.configBeforeFrozen
|
cfg := adapter.iter.cfg.configBeforeFrozen
|
||||||
cfg.UseNumber = true
|
cfg.UseNumber = true
|
||||||
adapter.iter.cfg = cfg.frozeWithCacheReuse()
|
adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisallowUnknownFields causes the Decoder to return an error when the destination
|
// DisallowUnknownFields causes the Decoder to return an error when the destination
|
||||||
|
@ -107,7 +109,7 @@ func (adapter *Decoder) UseNumber() {
|
||||||
func (adapter *Decoder) DisallowUnknownFields() {
|
func (adapter *Decoder) DisallowUnknownFields() {
|
||||||
cfg := adapter.iter.cfg.configBeforeFrozen
|
cfg := adapter.iter.cfg.configBeforeFrozen
|
||||||
cfg.DisallowUnknownFields = true
|
cfg.DisallowUnknownFields = true
|
||||||
adapter.iter.cfg = cfg.frozeWithCacheReuse()
|
adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder same as json.NewEncoder
|
// NewEncoder same as json.NewEncoder
|
||||||
|
@ -132,14 +134,14 @@ func (adapter *Encoder) Encode(val interface{}) error {
|
||||||
func (adapter *Encoder) SetIndent(prefix, indent string) {
|
func (adapter *Encoder) SetIndent(prefix, indent string) {
|
||||||
config := adapter.stream.cfg.configBeforeFrozen
|
config := adapter.stream.cfg.configBeforeFrozen
|
||||||
config.IndentionStep = len(indent)
|
config.IndentionStep = len(indent)
|
||||||
adapter.stream.cfg = config.frozeWithCacheReuse()
|
adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEscapeHTML escape html by default, set to false to disable
|
// SetEscapeHTML escape html by default, set to false to disable
|
||||||
func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) {
|
func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) {
|
||||||
config := adapter.stream.cfg.configBeforeFrozen
|
config := adapter.stream.cfg.configBeforeFrozen
|
||||||
config.EscapeHTML = escapeHTML
|
config.EscapeHTML = escapeHTML
|
||||||
adapter.stream.cfg = config.frozeWithCacheReuse()
|
adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid reports whether data is a valid JSON encoding.
|
// Valid reports whether data is a valid JSON encoding.
|
||||||
|
|
|
@ -74,7 +74,9 @@ type frozenConfig struct {
|
||||||
disallowUnknownFields bool
|
disallowUnknownFields bool
|
||||||
decoderCache *concurrent.Map
|
decoderCache *concurrent.Map
|
||||||
encoderCache *concurrent.Map
|
encoderCache *concurrent.Map
|
||||||
extensions []Extension
|
encoderExtension Extension
|
||||||
|
decoderExtension Extension
|
||||||
|
extraExtensions []Extension
|
||||||
streamPool *sync.Pool
|
streamPool *sync.Pool
|
||||||
iteratorPool *sync.Pool
|
iteratorPool *sync.Pool
|
||||||
caseSensitive bool
|
caseSensitive bool
|
||||||
|
@ -158,22 +160,21 @@ func (cfg Config) Froze() API {
|
||||||
if cfg.ValidateJsonRawMessage {
|
if cfg.ValidateJsonRawMessage {
|
||||||
api.validateJsonRawMessage(encoderExtension)
|
api.validateJsonRawMessage(encoderExtension)
|
||||||
}
|
}
|
||||||
if len(encoderExtension) > 0 {
|
api.encoderExtension = encoderExtension
|
||||||
api.extensions = append(api.extensions, encoderExtension)
|
api.decoderExtension = decoderExtension
|
||||||
}
|
|
||||||
if len(decoderExtension) > 0 {
|
|
||||||
api.extensions = append(api.extensions, decoderExtension)
|
|
||||||
}
|
|
||||||
api.configBeforeFrozen = cfg
|
api.configBeforeFrozen = cfg
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg Config) frozeWithCacheReuse() *frozenConfig {
|
func (cfg Config) frozeWithCacheReuse(extraExtensions []Extension) *frozenConfig {
|
||||||
api := getFrozenConfigFromCache(cfg)
|
api := getFrozenConfigFromCache(cfg)
|
||||||
if api != nil {
|
if api != nil {
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
api = cfg.Froze().(*frozenConfig)
|
api = cfg.Froze().(*frozenConfig)
|
||||||
|
for _, extension := range extraExtensions {
|
||||||
|
api.RegisterExtension(extension)
|
||||||
|
}
|
||||||
addFrozenConfigToCache(cfg, api)
|
addFrozenConfigToCache(cfg, api)
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
@ -190,7 +191,7 @@ func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) {
|
||||||
stream.WriteRaw(string(rawMessage))
|
stream.WriteRaw(string(rawMessage))
|
||||||
}
|
}
|
||||||
}, func(ptr unsafe.Pointer) bool {
|
}, func(ptr unsafe.Pointer) bool {
|
||||||
return false
|
return len(*((*json.RawMessage)(ptr))) == 0
|
||||||
}}
|
}}
|
||||||
extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder
|
extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder
|
||||||
extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder
|
extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder
|
||||||
|
@ -219,7 +220,9 @@ func (cfg *frozenConfig) getTagKey() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *frozenConfig) RegisterExtension(extension Extension) {
|
func (cfg *frozenConfig) RegisterExtension(extension Extension) {
|
||||||
cfg.extensions = append(cfg.extensions, extension)
|
cfg.extraExtensions = append(cfg.extraExtensions, extension)
|
||||||
|
copied := cfg.configBeforeFrozen
|
||||||
|
cfg.configBeforeFrozen = copied
|
||||||
}
|
}
|
||||||
|
|
||||||
type lossyFloat32Encoder struct {
|
type lossyFloat32Encoder struct {
|
||||||
|
@ -314,7 +317,7 @@ func (cfg *frozenConfig) MarshalIndent(v interface{}, prefix, indent string) ([]
|
||||||
}
|
}
|
||||||
newCfg := cfg.configBeforeFrozen
|
newCfg := cfg.configBeforeFrozen
|
||||||
newCfg.IndentionStep = len(indent)
|
newCfg.IndentionStep = len(indent)
|
||||||
return newCfg.frozeWithCacheReuse().Marshal(v)
|
return newCfg.frozeWithCacheReuse(cfg.extraExtensions).Marshal(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error {
|
func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unicode"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadObject read one field from object.
|
// ReadObject read one field from object.
|
||||||
|
@ -96,13 +96,12 @@ func (iter *Iterator) readFieldHash() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcHash(str string, caseSensitive bool) int64 {
|
func calcHash(str string, caseSensitive bool) int64 {
|
||||||
hash := int64(0x811c9dc5)
|
if !caseSensitive {
|
||||||
for _, b := range str {
|
str = strings.ToLower(str)
|
||||||
if caseSensitive {
|
|
||||||
hash ^= int64(b)
|
|
||||||
} else {
|
|
||||||
hash ^= int64(unicode.ToLower(b))
|
|
||||||
}
|
}
|
||||||
|
hash := int64(0x811c9dc5)
|
||||||
|
for _, b := range []byte(str) {
|
||||||
|
hash ^= int64(b)
|
||||||
hash *= 0x1000193
|
hash *= 0x1000193
|
||||||
}
|
}
|
||||||
return int64(hash)
|
return int64(hash)
|
||||||
|
|
|
@ -120,7 +120,8 @@ func decoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder {
|
||||||
for _, extension := range extensions {
|
for _, extension := range extensions {
|
||||||
decoder = extension.DecorateDecoder(typ, decoder)
|
decoder = extension.DecorateDecoder(typ, decoder)
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder)
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
decoder = extension.DecorateDecoder(typ, decoder)
|
decoder = extension.DecorateDecoder(typ, decoder)
|
||||||
}
|
}
|
||||||
return decoder
|
return decoder
|
||||||
|
@ -222,7 +223,8 @@ func encoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder {
|
||||||
for _, extension := range extensions {
|
for _, extension := range extensions {
|
||||||
encoder = extension.DecorateEncoder(typ, encoder)
|
encoder = extension.DecorateEncoder(typ, encoder)
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder)
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
encoder = extension.DecorateEncoder(typ, encoder)
|
encoder = extension.DecorateEncoder(typ, encoder)
|
||||||
}
|
}
|
||||||
return encoder
|
return encoder
|
||||||
|
|
|
@ -246,7 +246,8 @@ func getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
|
||||||
for _, extension := range extensions {
|
for _, extension := range extensions {
|
||||||
decoder = extension.DecorateDecoder(typ, decoder)
|
decoder = extension.DecorateDecoder(typ, decoder)
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder)
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
decoder = extension.DecorateDecoder(typ, decoder)
|
decoder = extension.DecorateDecoder(typ, decoder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,14 +260,18 @@ func _getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
|
||||||
return decoder
|
return decoder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
decoder := ctx.decoderExtension.CreateDecoder(typ)
|
||||||
|
if decoder != nil {
|
||||||
|
return decoder
|
||||||
|
}
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
decoder := extension.CreateDecoder(typ)
|
decoder := extension.CreateDecoder(typ)
|
||||||
if decoder != nil {
|
if decoder != nil {
|
||||||
return decoder
|
return decoder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typeName := typ.String()
|
typeName := typ.String()
|
||||||
decoder := typeDecoders[typeName]
|
decoder = typeDecoders[typeName]
|
||||||
if decoder != nil {
|
if decoder != nil {
|
||||||
return decoder
|
return decoder
|
||||||
}
|
}
|
||||||
|
@ -286,7 +291,8 @@ func getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
|
||||||
for _, extension := range extensions {
|
for _, extension := range extensions {
|
||||||
encoder = extension.DecorateEncoder(typ, encoder)
|
encoder = extension.DecorateEncoder(typ, encoder)
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder)
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
encoder = extension.DecorateEncoder(typ, encoder)
|
encoder = extension.DecorateEncoder(typ, encoder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,14 +306,18 @@ func _getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
|
||||||
return encoder
|
return encoder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
encoder := ctx.encoderExtension.CreateEncoder(typ)
|
||||||
|
if encoder != nil {
|
||||||
|
return encoder
|
||||||
|
}
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
encoder := extension.CreateEncoder(typ)
|
encoder := extension.CreateEncoder(typ)
|
||||||
if encoder != nil {
|
if encoder != nil {
|
||||||
return encoder
|
return encoder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typeName := typ.String()
|
typeName := typ.String()
|
||||||
encoder := typeEncoders[typeName]
|
encoder = typeEncoders[typeName]
|
||||||
if encoder != nil {
|
if encoder != nil {
|
||||||
return encoder
|
return encoder
|
||||||
}
|
}
|
||||||
|
@ -393,7 +403,9 @@ func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, em
|
||||||
for _, extension := range extensions {
|
for _, extension := range extensions {
|
||||||
extension.UpdateStructDescriptor(structDescriptor)
|
extension.UpdateStructDescriptor(structDescriptor)
|
||||||
}
|
}
|
||||||
for _, extension := range ctx.extensions {
|
ctx.encoderExtension.UpdateStructDescriptor(structDescriptor)
|
||||||
|
ctx.decoderExtension.UpdateStructDescriptor(structDescriptor)
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
extension.UpdateStructDescriptor(structDescriptor)
|
extension.UpdateStructDescriptor(structDescriptor)
|
||||||
}
|
}
|
||||||
processTags(structDescriptor, ctx.frozenConfig)
|
processTags(structDescriptor, ctx.frozenConfig)
|
||||||
|
|
|
@ -39,7 +39,11 @@ func encoderOfMap(ctx *ctx, typ reflect2.Type) ValEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
|
func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
|
||||||
for _, extension := range ctx.extensions {
|
decoder := ctx.decoderExtension.CreateMapKeyDecoder(typ)
|
||||||
|
if decoder != nil {
|
||||||
|
return decoder
|
||||||
|
}
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
decoder := extension.CreateMapKeyDecoder(typ)
|
decoder := extension.CreateMapKeyDecoder(typ)
|
||||||
if decoder != nil {
|
if decoder != nil {
|
||||||
return decoder
|
return decoder
|
||||||
|
@ -77,7 +81,11 @@ func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
|
func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
|
||||||
for _, extension := range ctx.extensions {
|
encoder := ctx.encoderExtension.CreateMapKeyEncoder(typ)
|
||||||
|
if encoder != nil {
|
||||||
|
return encoder
|
||||||
|
}
|
||||||
|
for _, extension := range ctx.extraExtensions {
|
||||||
encoder := extension.CreateMapKeyEncoder(typ)
|
encoder := extension.CreateMapKeyEncoder(typ)
|
||||||
if encoder != nil {
|
if encoder != nil {
|
||||||
return encoder
|
return encoder
|
||||||
|
|
Loading…
Reference in New Issue