mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* add DateTime sans mgo * change all uses of strfmt.DateTime to common.DateTime, remove test strfmt usage * remove api tests, system-test dep on api test multiple reasons to remove the api tests: * awkward dependency with fn_go meant generating bindings on a branched fn to vendor those to test new stuff. this is at a minimum not at all intuitive, worth it, nor a fun way to spend the finite amount of time we have to live. * api tests only tested a subset of functionality that the server/ api tests already test, and we risk having tests where one tests some thing and the other doesn't. let's not. we have too many test suites as it is, and these pretty much only test that we updated the fn_go bindings, which is actually a hassle as noted above and the cli will pretty quickly figure out anyway. * fn_go relies on openapi, which relies on mgo, which is deprecated and we'd like to remove as a dependency. openapi is a _huge_ dep built in a NIH fashion, that cannot simply remove the mgo dep as users may be using it. we've now stolen their date time and otherwise killed usage of it in fn core, for fn_go it still exists but that's less of a problem. * update deps removals: * easyjson * mgo * go-openapi * mapstructure * fn_go * purell * go-validator also, had to lock docker. we shouldn't use docker on master anyway, they strongly advise against that. had no luck with latest version rev, so i locked it to what we were using before. until next time. the rest is just playing dep roulette, those end up removing a ton tho * fix exec test to work * account for john le cache
97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
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
|
|
}
|