mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
添加依赖库
This commit is contained in:
15
vendor/github.com/cznic/fileutil/AUTHORS
generated
vendored
Normal file
15
vendor/github.com/cznic/fileutil/AUTHORS
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# This file lists authors for copyright purposes. This file is distinct from
|
||||
# the CONTRIBUTORS files. See the latter for an explanation.
|
||||
#
|
||||
# Names should be added to this file as:
|
||||
# Name or Organization <email address>
|
||||
#
|
||||
# The email address is not required for organizations.
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
CZ.NIC z.s.p.o. <kontakt@nic.cz>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Linelane GmbH <info@linelane.com>
|
||||
Aaron Bieber <deftly@gmail.com>
|
||||
|
||||
15
vendor/github.com/cznic/fileutil/CONTRIBUTORS
generated
vendored
Normal file
15
vendor/github.com/cznic/fileutil/CONTRIBUTORS
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# This file lists people who contributed code to this repository. The AUTHORS
|
||||
# file lists the copyright holders; this file lists people.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Andris Valums <info@linelane.com>
|
||||
Bill Thiede <xinu.tv>
|
||||
Gary Burd <gary@beagledreams.com>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Nick Owens <mischief@offblast.org>
|
||||
Tamás Gulácsi <gt-dev@gthomas.eu>
|
||||
Aaron Bieber <deftly@gmail.com>
|
||||
27
vendor/github.com/cznic/fileutil/LICENSE
generated
vendored
Normal file
27
vendor/github.com/cznic/fileutil/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
27
vendor/github.com/cznic/fileutil/Makefile
generated
vendored
Normal file
27
vendor/github.com/cznic/fileutil/Makefile
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Copyright (c) 2014 The fileutil authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: all clean editor todo
|
||||
|
||||
all: editor
|
||||
go vet
|
||||
golint .
|
||||
go install
|
||||
make todo
|
||||
|
||||
editor:
|
||||
go fmt
|
||||
go test -i
|
||||
go test
|
||||
go build
|
||||
|
||||
todo:
|
||||
@grep -n ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* *.go || true
|
||||
@grep -n TODO *.go || true
|
||||
@grep -n BUG *.go || true
|
||||
@grep -n println *.go || true
|
||||
|
||||
clean:
|
||||
@go clean
|
||||
rm -f y.output
|
||||
16
vendor/github.com/cznic/fileutil/README
generated
vendored
Normal file
16
vendor/github.com/cznic/fileutil/README
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
This is a goinstall-able mirror of modified code already published at:
|
||||
http://git.nic.cz/redmine/projects/gofileutil/repository
|
||||
|
||||
Packages in this repository:
|
||||
|
||||
Install: $go get github.com/cznic/fileutil
|
||||
Godocs: http://godoc.org/github.com/cznic/fileutil
|
||||
|
||||
Install: $go get github.com/cznic/fileutil/storage
|
||||
Godocs: http://godoc.org/github.com/cznic/fileutil/storage
|
||||
|
||||
Install: $go get github.com/cznic/fileutil/falloc
|
||||
Godocs: http://godoc.org/github.com/cznic/fileutil/falloc
|
||||
|
||||
Install: $go get github.com/cznic/fileutil/hdb
|
||||
Godocs: http://godoc.org/github.com/cznic/fileutil/hdb
|
||||
223
vendor/github.com/cznic/fileutil/fileutil.go
generated
vendored
Normal file
223
vendor/github.com/cznic/fileutil/fileutil.go
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package fileutil collects some file utility functions.
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GoMFile is a concurrent access safe version of MFile.
|
||||
type GoMFile struct {
|
||||
mfile *MFile
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// NewGoMFile return a newly created GoMFile.
|
||||
func NewGoMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *GoMFile, err error) {
|
||||
m = &GoMFile{}
|
||||
if m.mfile, err = NewMFile(fname, flag, perm, delta_ns); err != nil {
|
||||
m = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *GoMFile) File() (file *os.File, err error) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
return m.mfile.File()
|
||||
}
|
||||
|
||||
func (m *GoMFile) SetChanged() {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
m.mfile.SetChanged()
|
||||
}
|
||||
|
||||
func (m *GoMFile) SetHandler(h MFileHandler) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
m.mfile.SetHandler(h)
|
||||
}
|
||||
|
||||
// MFileHandler resolves modifications of File.
|
||||
// Possible File context is expected to be a part of the handler's closure.
|
||||
type MFileHandler func(*os.File) error
|
||||
|
||||
// MFile represents an os.File with a guard/handler on change/modification.
|
||||
// Example use case is an app with a configuration file which can be modified at any time
|
||||
// and have to be reloaded in such event prior to performing something configurable by that
|
||||
// file. The checks are made only on access to the MFile file by
|
||||
// File() and a time threshold/hysteresis value can be chosen on creating a new MFile.
|
||||
type MFile struct {
|
||||
file *os.File
|
||||
handler MFileHandler
|
||||
t0 int64
|
||||
delta int64
|
||||
ctime int64
|
||||
}
|
||||
|
||||
// NewMFile returns a newly created MFile or Error if any.
|
||||
// The fname, flag and perm parameters have the same meaning as in os.Open.
|
||||
// For meaning of the delta_ns parameter please see the (m *MFile) File() docs.
|
||||
func NewMFile(fname string, flag int, perm os.FileMode, delta_ns int64) (m *MFile, err error) {
|
||||
m = &MFile{}
|
||||
m.t0 = time.Now().UnixNano()
|
||||
if m.file, err = os.OpenFile(fname, flag, perm); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var fi os.FileInfo
|
||||
if fi, err = m.file.Stat(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.ctime = fi.ModTime().UnixNano()
|
||||
m.delta = delta_ns
|
||||
runtime.SetFinalizer(m, func(m *MFile) {
|
||||
m.file.Close()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// SetChanged forces next File() to unconditionally handle modification of the wrapped os.File.
|
||||
func (m *MFile) SetChanged() {
|
||||
m.ctime = -1
|
||||
}
|
||||
|
||||
// SetHandler sets a function to be invoked when modification of MFile is to be processed.
|
||||
func (m *MFile) SetHandler(h MFileHandler) {
|
||||
m.handler = h
|
||||
}
|
||||
|
||||
// File returns an os.File from MFile. If time elapsed between the last invocation of this function
|
||||
// and now is at least delta_ns ns (a parameter of NewMFile) then the file is checked for
|
||||
// change/modification. For delta_ns == 0 the modification is checked w/o getting os.Time().
|
||||
// If a change is detected a handler is invoked on the MFile file.
|
||||
// Any of these steps can produce an Error. If that happens the function returns nil, Error.
|
||||
func (m *MFile) File() (file *os.File, err error) {
|
||||
var now int64
|
||||
|
||||
mustCheck := m.delta == 0
|
||||
if !mustCheck {
|
||||
now = time.Now().UnixNano()
|
||||
mustCheck = now-m.t0 > m.delta
|
||||
}
|
||||
|
||||
if mustCheck { // check interval reached
|
||||
var fi os.FileInfo
|
||||
if fi, err = m.file.Stat(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if fi.ModTime().UnixNano() != m.ctime { // modification detected
|
||||
if m.handler == nil {
|
||||
return nil, fmt.Errorf("no handler set for modified file %q", m.file.Name())
|
||||
}
|
||||
if err = m.handler(m.file); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.ctime = fi.ModTime().UnixNano()
|
||||
}
|
||||
m.t0 = now
|
||||
}
|
||||
|
||||
return m.file, nil
|
||||
}
|
||||
|
||||
// Read reads buf from r. It will either fill the full buf or fail.
|
||||
// It wraps the functionality of an io.Reader which may return less bytes than requested,
|
||||
// but may block if not all data are ready for the io.Reader.
|
||||
func Read(r io.Reader, buf []byte) (err error) {
|
||||
have := 0
|
||||
remain := len(buf)
|
||||
got := 0
|
||||
for remain > 0 {
|
||||
if got, err = r.Read(buf[have:]); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
remain -= got
|
||||
have += got
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// "os" and/or "syscall" extensions
|
||||
|
||||
// FadviseAdvice is used by Fadvise.
|
||||
type FadviseAdvice int
|
||||
|
||||
// FAdviseAdvice values.
|
||||
const (
|
||||
// $ grep FADV /usr/include/bits/fcntl.h
|
||||
POSIX_FADV_NORMAL FadviseAdvice = iota // No further special treatment.
|
||||
POSIX_FADV_RANDOM // Expect random page references.
|
||||
POSIX_FADV_SEQUENTIAL // Expect sequential page references.
|
||||
POSIX_FADV_WILLNEED // Will need these pages.
|
||||
POSIX_FADV_DONTNEED // Don't need these pages.
|
||||
POSIX_FADV_NOREUSE // Data will be accessed once.
|
||||
)
|
||||
|
||||
// TempFile creates a new temporary file in the directory dir with a name
|
||||
// ending with suffix, basename starting with prefix, opens the file for
|
||||
// reading and writing, and returns the resulting *os.File. If dir is the
|
||||
// empty string, TempFile uses the default directory for temporary files (see
|
||||
// os.TempDir). Multiple programs calling TempFile simultaneously will not
|
||||
// choose the same file. The caller can use f.Name() to find the pathname of
|
||||
// the file. It is the caller's responsibility to remove the file when no
|
||||
// longer needed.
|
||||
//
|
||||
// NOTE: This function differs from ioutil.TempFile.
|
||||
func TempFile(dir, prefix, suffix string) (f *os.File, err error) {
|
||||
if dir == "" {
|
||||
dir = os.TempDir()
|
||||
}
|
||||
|
||||
nconflict := 0
|
||||
for i := 0; i < 10000; i++ {
|
||||
name := filepath.Join(dir, prefix+nextInfix()+suffix)
|
||||
f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if os.IsExist(err) {
|
||||
if nconflict++; nconflict > 10 {
|
||||
rand = reseed()
|
||||
}
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Random number state.
|
||||
// We generate random temporary file names so that there's a good
|
||||
// chance the file doesn't exist yet - keeps the number of tries in
|
||||
// TempFile to a minimum.
|
||||
var rand uint32
|
||||
var randmu sync.Mutex
|
||||
|
||||
func reseed() uint32 {
|
||||
return uint32(time.Now().UnixNano() + int64(os.Getpid()))
|
||||
}
|
||||
|
||||
func nextInfix() string {
|
||||
randmu.Lock()
|
||||
r := rand
|
||||
if r == 0 {
|
||||
r = reseed()
|
||||
}
|
||||
r = r*1664525 + 1013904223 // constants from Numerical Recipes
|
||||
rand = r
|
||||
randmu.Unlock()
|
||||
return strconv.Itoa(int(1e9 + r%1e9))[1:]
|
||||
}
|
||||
27
vendor/github.com/cznic/fileutil/fileutil_arm.go
generated
vendored
Normal file
27
vendor/github.com/cznic/fileutil/fileutil_arm.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Not supported on ARM.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Not supported on ARM.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
29
vendor/github.com/cznic/fileutil/fileutil_darwin.go
generated
vendored
Normal file
29
vendor/github.com/cznic/fileutil/fileutil_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2014 The fileutil 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 !arm
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Not supported on OSX.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Not supported on OSX.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
29
vendor/github.com/cznic/fileutil/fileutil_freebsd.go
generated
vendored
Normal file
29
vendor/github.com/cznic/fileutil/fileutil_freebsd.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2014 The fileutil 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 !arm
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Unimplemented on FreeBSD.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Unimplemented on FreeBSD.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
98
vendor/github.com/cznic/fileutil/fileutil_linux.go
generated
vendored
Normal file
98
vendor/github.com/cznic/fileutil/fileutil_linux.go
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2014 The fileutil 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 !arm
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const hasPunchHole = true
|
||||
|
||||
func n(s []byte) byte {
|
||||
for i, c := range s {
|
||||
if c < '0' || c > '9' {
|
||||
s = s[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
v, _ := strconv.Atoi(string(s))
|
||||
return byte(v)
|
||||
}
|
||||
|
||||
func init() {
|
||||
b, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tokens := bytes.Split(b, []byte("."))
|
||||
if len(tokens) > 3 {
|
||||
tokens = tokens[:3]
|
||||
}
|
||||
switch len(tokens) {
|
||||
case 3:
|
||||
// Supported since kernel 2.6.38
|
||||
if bytes.Compare([]byte{n(tokens[0]), n(tokens[1]), n(tokens[2])}, []byte{2, 6, 38}) < 0 {
|
||||
puncher = func(*os.File, int64, int64) error { return nil }
|
||||
}
|
||||
case 2:
|
||||
if bytes.Compare([]byte{n(tokens[0]), n(tokens[1])}, []byte{2, 7}) < 0 {
|
||||
puncher = func(*os.File, int64, int64) error { return nil }
|
||||
}
|
||||
default:
|
||||
puncher = func(*os.File, int64, int64) error { return nil }
|
||||
}
|
||||
}
|
||||
|
||||
var puncher = func(f *os.File, off, len int64) error {
|
||||
const (
|
||||
/*
|
||||
/usr/include/linux$ grep FL_ falloc.h
|
||||
*/
|
||||
_FALLOC_FL_KEEP_SIZE = 0x01 // default is extend size
|
||||
_FALLOC_FL_PUNCH_HOLE = 0x02 // de-allocates range
|
||||
)
|
||||
|
||||
_, _, errno := syscall.Syscall6(
|
||||
syscall.SYS_FALLOCATE,
|
||||
uintptr(f.Fd()),
|
||||
uintptr(_FALLOC_FL_KEEP_SIZE|_FALLOC_FL_PUNCH_HOLE),
|
||||
uintptr(off),
|
||||
uintptr(len),
|
||||
0, 0)
|
||||
if errno != 0 {
|
||||
return os.NewSyscallError("SYS_FALLOCATE", errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. No-op for kernels < 2.6.38 (or < 2.7).
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return puncher(f, off, len)
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
_, _, errno := syscall.Syscall6(
|
||||
syscall.SYS_FADVISE64,
|
||||
uintptr(f.Fd()),
|
||||
uintptr(off),
|
||||
uintptr(len),
|
||||
uintptr(advice),
|
||||
0, 0)
|
||||
return os.NewSyscallError("SYS_FADVISE64", errno)
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
29
vendor/github.com/cznic/fileutil/fileutil_netbsd.go
generated
vendored
Normal file
29
vendor/github.com/cznic/fileutil/fileutil_netbsd.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2014 The fileutil 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 !arm
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Similar to FreeBSD, this is
|
||||
// unimplemented.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unimplemented on NetBSD.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
27
vendor/github.com/cznic/fileutil/fileutil_openbsd.go
generated
vendored
Normal file
27
vendor/github.com/cznic/fileutil/fileutil_openbsd.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Similar to FreeBSD, this is
|
||||
// unimplemented.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unimplemented on OpenBSD.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
27
vendor/github.com/cznic/fileutil/fileutil_plan9.go
generated
vendored
Normal file
27
vendor/github.com/cznic/fileutil/fileutil_plan9.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Unimplemented on Plan 9.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Unimplemented on Plan 9.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
29
vendor/github.com/cznic/fileutil/fileutil_solaris.go
generated
vendored
Normal file
29
vendor/github.com/cznic/fileutil/fileutil_solaris.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2013 jnml. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build go1.3
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const hasPunchHole = false
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Not supported on Solaris.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Not supported on Solaris.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool { return err == io.EOF }
|
||||
185
vendor/github.com/cznic/fileutil/fileutil_windows.go
generated
vendored
Normal file
185
vendor/github.com/cznic/fileutil/fileutil_windows.go
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const hasPunchHole = true
|
||||
|
||||
// PunchHole deallocates space inside a file in the byte range starting at
|
||||
// offset and continuing for len bytes. Not supported on Windows.
|
||||
func PunchHole(f *os.File, off, len int64) error {
|
||||
return puncher(f, off, len)
|
||||
}
|
||||
|
||||
// Fadvise predeclares an access pattern for file data. See also 'man 2
|
||||
// posix_fadvise'. Not supported on Windows.
|
||||
func Fadvise(f *os.File, off, len int64, advice FadviseAdvice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEOF reports whether err is an EOF condition.
|
||||
func IsEOF(err error) bool {
|
||||
if err == io.EOF {
|
||||
return true
|
||||
}
|
||||
|
||||
// http://social.technet.microsoft.com/Forums/windowsserver/en-US/1a16311b-c625-46cf-830b-6a26af488435/how-to-solve-error-38-0x26-errorhandleeof-using-fsctlgetretrievalpointers
|
||||
x, ok := err.(*os.PathError)
|
||||
return ok && x.Op == "read" && x.Err.(syscall.Errno) == 0x26
|
||||
}
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
|
||||
procDeviceIOControl = modkernel32.NewProc("DeviceIoControl")
|
||||
|
||||
sparseFilesMu sync.Mutex
|
||||
sparseFiles map[uintptr]struct{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
// sparseFiles is an fd set for already "sparsed" files - according to
|
||||
// msdn.microsoft.com/en-us/library/windows/desktop/aa364225(v=vs.85).aspx
|
||||
// the file handles are unique per process.
|
||||
sparseFiles = make(map[uintptr]struct{})
|
||||
}
|
||||
|
||||
// puncHoleWindows punches a hole into the given file starting at offset,
|
||||
// measuring "size" bytes
|
||||
// (http://msdn.microsoft.com/en-us/library/windows/desktop/aa364597%28v=vs.85%29.aspx)
|
||||
func puncher(file *os.File, offset, size int64) error {
|
||||
if err := ensureFileSparse(file); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364411%28v=vs.85%29.aspx
|
||||
// typedef struct _FILE_ZERO_DATA_INFORMATION {
|
||||
// LARGE_INTEGER FileOffset;
|
||||
// LARGE_INTEGER BeyondFinalZero;
|
||||
//} FILE_ZERO_DATA_INFORMATION, *PFILE_ZERO_DATA_INFORMATION;
|
||||
type fileZeroDataInformation struct {
|
||||
FileOffset, BeyondFinalZero int64
|
||||
}
|
||||
|
||||
lpInBuffer := fileZeroDataInformation{
|
||||
FileOffset: offset,
|
||||
BeyondFinalZero: offset + size}
|
||||
return deviceIOControl(false, file.Fd(), uintptr(unsafe.Pointer(&lpInBuffer)), 16)
|
||||
}
|
||||
|
||||
// // http://msdn.microsoft.com/en-us/library/windows/desktop/cc948908%28v=vs.85%29.aspx
|
||||
// type fileSetSparseBuffer struct {
|
||||
// SetSparse bool
|
||||
// }
|
||||
|
||||
func ensureFileSparse(file *os.File) (err error) {
|
||||
fd := file.Fd()
|
||||
sparseFilesMu.Lock()
|
||||
if _, ok := sparseFiles[fd]; ok {
|
||||
sparseFilesMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = deviceIOControl(true, fd, 0, 0); err == nil {
|
||||
sparseFiles[fd] = struct{}{}
|
||||
}
|
||||
sparseFilesMu.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
func deviceIOControl(setSparse bool, fd, inBuf, inBufLen uintptr) (err error) {
|
||||
const (
|
||||
//http://source.winehq.org/source/include/winnt.h#L4605
|
||||
file_read_data = 1
|
||||
file_write_data = 2
|
||||
|
||||
// METHOD_BUFFERED 0
|
||||
method_buffered = 0
|
||||
// FILE_ANY_ACCESS 0
|
||||
file_any_access = 0
|
||||
// FILE_DEVICE_FILE_SYSTEM 0x00000009
|
||||
file_device_file_system = 0x00000009
|
||||
// FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
|
||||
file_special_access = file_any_access
|
||||
file_read_access = file_read_data
|
||||
file_write_access = file_write_data
|
||||
|
||||
// http://source.winehq.org/source/include/winioctl.h
|
||||
// #define CTL_CODE ( DeviceType,
|
||||
// Function,
|
||||
// Method,
|
||||
// Access )
|
||||
// ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
|
||||
|
||||
// FSCTL_SET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
||||
fsctl_set_compression = (file_device_file_system << 16) | ((file_read_access | file_write_access) << 14) | (16 << 2) | method_buffered
|
||||
// FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
|
||||
fsctl_set_sparse = (file_device_file_system << 16) | (file_special_access << 14) | (49 << 2) | method_buffered
|
||||
// FSCTL_SET_ZERO_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 50, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
fsctl_set_zero_data = (file_device_file_system << 16) | (file_write_data << 14) | (50 << 2) | method_buffered
|
||||
)
|
||||
retPtr := uintptr(unsafe.Pointer(&(make([]byte, 8)[0])))
|
||||
var r1 uintptr
|
||||
var e1 syscall.Errno
|
||||
if setSparse {
|
||||
// BOOL
|
||||
// WINAPI
|
||||
// DeviceIoControl( (HANDLE) hDevice, // handle to a file
|
||||
// FSCTL_SET_SPARSE, // dwIoControlCode
|
||||
// (PFILE_SET_SPARSE_BUFFER) lpInBuffer, // input buffer
|
||||
// (DWORD) nInBufferSize, // size of input buffer
|
||||
// NULL, // lpOutBuffer
|
||||
// 0, // nOutBufferSize
|
||||
// (LPDWORD) lpBytesReturned, // number of bytes returned
|
||||
// (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure
|
||||
r1, _, e1 = syscall.Syscall9(procDeviceIOControl.Addr(), 8,
|
||||
fd,
|
||||
uintptr(fsctl_set_sparse),
|
||||
// If the lpInBuffer parameter is NULL, the operation will behave the same as if the SetSparse member of the FILE_SET_SPARSE_BUFFER structure were TRUE. In other words, the operation sets the file to a sparse file.
|
||||
0, // uintptr(unsafe.Pointer(&lpInBuffer)),
|
||||
0, // 1,
|
||||
0,
|
||||
0,
|
||||
retPtr,
|
||||
0,
|
||||
0)
|
||||
} else {
|
||||
// BOOL
|
||||
// WINAPI
|
||||
// DeviceIoControl( (HANDLE) hDevice, // handle to a file
|
||||
// FSCTL_SET_ZERO_DATA, // dwIoControlCode
|
||||
// (LPVOID) lpInBuffer, // input buffer
|
||||
// (DWORD) nInBufferSize, // size of input buffer
|
||||
// NULL, // lpOutBuffer
|
||||
// 0, // nOutBufferSize
|
||||
// (LPDWORD) lpBytesReturned, // number of bytes returned
|
||||
// (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure
|
||||
r1, _, e1 = syscall.Syscall9(procDeviceIOControl.Addr(), 8,
|
||||
fd,
|
||||
uintptr(fsctl_set_zero_data),
|
||||
inBuf,
|
||||
inBufLen,
|
||||
0,
|
||||
0,
|
||||
retPtr,
|
||||
0,
|
||||
0)
|
||||
}
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
err = error(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
13
vendor/github.com/cznic/fileutil/test_deps.go
generated
vendored
Normal file
13
vendor/github.com/cznic/fileutil/test_deps.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// blame: jnml, labs.nic.cz
|
||||
|
||||
package fileutil
|
||||
|
||||
// Pull test dependencies too.
|
||||
// Enables easy 'go test X' after 'go get X'
|
||||
import (
|
||||
// nothing yet
|
||||
)
|
||||
Reference in New Issue
Block a user