Files
weave-scope/vendor/github.com/Microsoft/go-winio/reparse.go
Marc Carré a74f203668 Update fsouza/go-dockerclient to v1.2.0
```
gvt delete github.com/fsouza/go-dockerclient
gvt delete github.com/docker/docker/opts
gvt delete github.com/docker/docker/pkg/archive
gvt delete github.com/docker/docker/pkg/fileutils
gvt delete github.com/docker/docker/pkg/homedir
gvt delete github.com/docker/docker/pkg/idtools
gvt delete github.com/docker/docker/pkg/ioutils
gvt delete github.com/docker/docker/pkg/longpath
gvt delete github.com/docker/docker/pkg/mflag
gvt delete github.com/docker/docker/pkg/mount
gvt delete github.com/docker/docker/pkg/parsers
gvt delete github.com/docker/docker/pkg/pools
gvt delete github.com/docker/docker/pkg/promise
gvt delete github.com/docker/docker/pkg/stdcopy
gvt delete github.com/docker/docker/pkg/system
gvt delete github.com/docker/docker/pkg/term
gvt delete github.com/docker/docker/pkg/units
gvt delete github.com/docker/libcontainer/cgroups
gvt delete github.com/docker/distribution/digest
gvt delete github.com/docker/distribution/reference
gvt delete github.com/docker/distribution/vendor/github.com/stevvooe/resumable
gvt fetch --tag 1.2.0 github.com/fsouza/go-dockerclient
2018/07/23 17:03:36 Fetching: github.com/fsouza/go-dockerclient
2018/07/23 17:03:39 · Skipping (existing): github.com/docker/go-units
2018/07/23 17:03:39 · Fetching recursive dependency: github.com/docker/docker/pkg/jsonmessage
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Nvveen/Gotty
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-units
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/pkg/term
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Azure/go-ansiterm
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/sirupsen/logrus
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/unix
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/crypto/ssh/terminal
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/windows
2018/07/23 17:03:51 · Skipping (existing): github.com/gorilla/mux
2018/07/23 17:03:51 · Fetching recursive dependency: github.com/docker/docker/api/types/swarm
2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/api/types/network
2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/api/types/filters
2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/api/types/versions
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-connections/nat
2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/api/types
2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/errdefs
2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/pkg/streamformatter
2018/07/23 17:03:51 ······· Fetching recursive dependency: github.com/docker/docker/pkg/progress
2018/07/23 17:03:51 ········ Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/time/rate
2018/07/23 17:03:51 ········· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/net/context
2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/gogo/protobuf/proto
2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go/v1
2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/go-digest
2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/homedir
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/idtools
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/system
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/pkg/errors
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Microsoft/go-winio
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/containerd/continuity/pathdriver
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/mount
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/user
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/stdcopy
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/archive
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/pools
2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/ioutils
2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/longpath
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/system
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/fileutils
2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/archive/tar
2018/07/23 17:03:52 · Skipping (existing): golang.org/x/net/context
2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/opts
2018/07/23 17:03:53 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/libnetwork/ipamutils
2018/07/23 17:03:53 · Skipping (existing): golang.org/x/net/context/ctxhttp
2018/07/23 17:03:53 · Fetching recursive dependency: github.com/Microsoft/go-winio
2018/07/23 17:03:55 ·· Fetching recursive dependency: golang.org/x/sys/windows
```
2018-07-23 20:10:16 +02:00

129 lines
3.4 KiB
Go

package winio
import (
"bytes"
"encoding/binary"
"fmt"
"strings"
"unicode/utf16"
"unsafe"
)
const (
reparseTagMountPoint = 0xA0000003
reparseTagSymlink = 0xA000000C
)
type reparseDataBuffer struct {
ReparseTag uint32
ReparseDataLength uint16
Reserved uint16
SubstituteNameOffset uint16
SubstituteNameLength uint16
PrintNameOffset uint16
PrintNameLength uint16
}
// ReparsePoint describes a Win32 symlink or mount point.
type ReparsePoint struct {
Target string
IsMountPoint bool
}
// UnsupportedReparsePointError is returned when trying to decode a non-symlink or
// mount point reparse point.
type UnsupportedReparsePointError struct {
Tag uint32
}
func (e *UnsupportedReparsePointError) Error() string {
return fmt.Sprintf("unsupported reparse point %x", e.Tag)
}
// DecodeReparsePoint decodes a Win32 REPARSE_DATA_BUFFER structure containing either a symlink
// or a mount point.
func DecodeReparsePoint(b []byte) (*ReparsePoint, error) {
tag := binary.LittleEndian.Uint32(b[0:4])
return DecodeReparsePointData(tag, b[8:])
}
func DecodeReparsePointData(tag uint32, b []byte) (*ReparsePoint, error) {
isMountPoint := false
switch tag {
case reparseTagMountPoint:
isMountPoint = true
case reparseTagSymlink:
default:
return nil, &UnsupportedReparsePointError{tag}
}
nameOffset := 8 + binary.LittleEndian.Uint16(b[4:6])
if !isMountPoint {
nameOffset += 4
}
nameLength := binary.LittleEndian.Uint16(b[6:8])
name := make([]uint16, nameLength/2)
err := binary.Read(bytes.NewReader(b[nameOffset:nameOffset+nameLength]), binary.LittleEndian, &name)
if err != nil {
return nil, err
}
return &ReparsePoint{string(utf16.Decode(name)), isMountPoint}, nil
}
func isDriveLetter(c byte) bool {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}
// EncodeReparsePoint encodes a Win32 REPARSE_DATA_BUFFER structure describing a symlink or
// mount point.
func EncodeReparsePoint(rp *ReparsePoint) []byte {
// Generate an NT path and determine if this is a relative path.
var ntTarget string
relative := false
if strings.HasPrefix(rp.Target, `\\?\`) {
ntTarget = `\??\` + rp.Target[4:]
} else if strings.HasPrefix(rp.Target, `\\`) {
ntTarget = `\??\UNC\` + rp.Target[2:]
} else if len(rp.Target) >= 2 && isDriveLetter(rp.Target[0]) && rp.Target[1] == ':' {
ntTarget = `\??\` + rp.Target
} else {
ntTarget = rp.Target
relative = true
}
// The paths must be NUL-terminated even though they are counted strings.
target16 := utf16.Encode([]rune(rp.Target + "\x00"))
ntTarget16 := utf16.Encode([]rune(ntTarget + "\x00"))
size := int(unsafe.Sizeof(reparseDataBuffer{})) - 8
size += len(ntTarget16)*2 + len(target16)*2
tag := uint32(reparseTagMountPoint)
if !rp.IsMountPoint {
tag = reparseTagSymlink
size += 4 // Add room for symlink flags
}
data := reparseDataBuffer{
ReparseTag: tag,
ReparseDataLength: uint16(size),
SubstituteNameOffset: 0,
SubstituteNameLength: uint16((len(ntTarget16) - 1) * 2),
PrintNameOffset: uint16(len(ntTarget16) * 2),
PrintNameLength: uint16((len(target16) - 1) * 2),
}
var b bytes.Buffer
binary.Write(&b, binary.LittleEndian, &data)
if !rp.IsMountPoint {
flags := uint32(0)
if relative {
flags |= 1
}
binary.Write(&b, binary.LittleEndian, flags)
}
binary.Write(&b, binary.LittleEndian, ntTarget16)
binary.Write(&b, binary.LittleEndian, target16)
return b.Bytes()
}