package cgroupbpf

import (
	"bytes"
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"time"
)

func bindataRead(data []byte, name string) ([]byte, error) {
	gz, err := gzip.NewReader(bytes.NewBuffer(data))
	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}

	var buf bytes.Buffer
	_, err = io.Copy(&buf, gz)
	clErr := gz.Close()

	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}
	if clErr != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}

type asset struct {
	bytes []byte
	info  os.FileInfo
}

type bindataFileInfo struct {
	name    string
	size    int64
	mode    os.FileMode
	modTime time.Time
}

func (fi bindataFileInfo) Name() string {
	return fi.name
}
func (fi bindataFileInfo) Size() int64 {
	return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
	return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
	return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
	return false
}
func (fi bindataFileInfo) Sys() interface{} {
	return nil
}

var _datapathBpfO = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x53\xcf\x8a\xd3\x40\x1c\xfe\x26\xc9\xa6\xd9\x5d\x0f\xab\x74\x65\x29\x8b\xf4\x22\xde\xb2\x95\xc5\xa3\xb0\xac\xa8\x07\x7b\x58\x14\x11\x44\x88\x69\x98\xd6\x6a\xa2\x69\x12\x41\x45\xd0\x83\x05\x5f\xc0\x07\x50\x41\x7c\x83\x1c\xdb\xa3\x8f\xd1\x83\x87\x1e\xf5\xa4\xb7\x91\x4c\x7e\xd3\x86\x69\x4a\xfd\x41\xe6\xcb\xf7\xf1\xfb\xcf\xcc\xbb\x9b\xdd\x5b\x06\x63\x50\xc6\xf0\x07\x4b\xb6\xb4\xef\xc6\xf2\xff\x84\xce\x1d\x30\xf8\x17\x1f\x49\x76\xdf\xde\x91\x98\xdb\xa5\xcf\xe4\x6b\x89\x0d\x13\x98\x0b\x21\x72\x8a\xcf\x2d\xa0\x09\x60\x0c\xa0\x05\x60\xf4\x79\x2e\x0a\xfd\x01\x03\x7e\x15\x79\x18\x93\xf9\xfd\x6f\x7f\xa5\x1e\x3c\xfd\x29\x31\x67\x40\xbb\xe0\xad\x99\xe4\x93\x2f\x94\xdf\x00\x66\x42\x88\x03\xad\xe9\xb1\x9c\x05\x98\x90\x9e\x13\xdf\xa7\x59\x73\xf2\xfb\x44\xb8\x0b\xc0\x01\x60\x01\x78\xff\xe1\x92\xf4\xbd\x7d\xd6\xc5\x9e\xda\xcb\x9b\xbb\x70\xde\xee\xb2\x73\x00\x0e\xe8\x53\xf6\xa3\x66\x5f\xba\x5d\x97\xb9\x7f\x0b\x5d\x7f\x28\x4f\x13\x8f\x35\xfd\x1e\xe9\xd3\x9a\x5c\x26\xcc\x15\xed\x32\x80\xf3\xb0\x17\xdc\x22\x6c\x00\xb8\x50\xf1\x57\xbd\xb6\xa4\xff\xd6\x42\x6f\x12\x7e\x24\x64\x14\x7b\x58\xe1\x32\xa7\x9b\xf1\x57\x19\xfa\xc3\x30\xe3\x89\xc7\x07\x09\x4f\x53\x44\x7e\x9c\x22\x8c\x23\xaf\x94\xe1\x79\xe1\x30\xe0\xcf\x53\x0e\x37\xe1\xa1\xcb\x9f\x78\xfd\xc4\x8f\x38\x7a\x71\xdf\x0d\xe0\xa6\x59\x92\xf9\x3d\xb8\xe9\xeb\xa8\xc0\xee\xe9\x69\xc7\xbb\x56\xc2\xb1\x8c\x08\x06\xc9\x8b\x97\xf1\x51\xfa\xac\x77\x75\xe3\x62\xff\xd3\x6e\xc8\xbd\xad\x5a\x87\xee\xe5\x48\xd3\xf5\x37\xc0\xe8\xb3\x35\xfd\x64\x4d\x3d\x4b\xe3\x7c\x43\xbc\x7e\x87\x1c\x8d\xfb\x00\xb6\x6b\xea\xec\x51\xff\xea\x9e\x6e\xd3\x9c\x2a\x5e\xe9\xfb\x54\x5f\xdf\x81\x43\x83\x36\x37\xf4\x7f\x65\x4d\xfc\x21\xab\xf7\xd7\xf7\x77\x4c\x9a\xa1\xe9\x6d\x72\xec\xe8\x7d\x69\xfc\x68\xcd\xfc\xed\x9a\xf9\x1b\x35\xf3\xdf\xa9\xa9\x5d\xd8\x19\xd5\x9f\x56\xfa\xde\xaa\xc4\xab\x77\xfe\x2f\x00\x00\xff\xff\xe2\x19\x8e\xe6\x28\x05\x00\x00")

func datapathBpfOBytes() ([]byte, error) {
	return bindataRead(
		_datapathBpfO,
		"datapath/bpf.o",
	)
}

func datapathBpfO() (*asset, error) {
	bytes, err := datapathBpfOBytes()
	if err != nil {
		return nil, err
	}

	info := bindataFileInfo{name: "datapath/bpf.o", size: 1320, mode: os.FileMode(436), modTime: time.Unix(1, 0)}
	a := &asset{bytes: bytes, info: info}
	return a, nil
}

func Asset(name string) ([]byte, error) {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	if f, ok := _bindata[cannonicalName]; ok {
		a, err := f()
		if err != nil {
			return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
		}
		return a.bytes, nil
	}
	return nil, fmt.Errorf("Asset %s not found", name)
}

func MustAsset(name string) []byte {
	a, err := Asset(name)
	if err != nil {
		panic("asset: Asset(" + name + "): " + err.Error())
	}

	return a
}

func AssetInfo(name string) (os.FileInfo, error) {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	if f, ok := _bindata[cannonicalName]; ok {
		a, err := f()
		if err != nil {
			return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
		}
		return a.info, nil
	}
	return nil, fmt.Errorf("AssetInfo %s not found", name)
}

func AssetNames() []string {
	names := make([]string, 0, len(_bindata))
	for name := range _bindata {
		names = append(names, name)
	}
	return names
}

var _bindata = map[string]func() (*asset, error){
	"datapath/bpf.o": datapathBpfO,
}

func AssetDir(name string) ([]string, error) {
	node := _bintree
	if len(name) != 0 {
		cannonicalName := strings.Replace(name, "\\", "/", -1)
		pathList := strings.Split(cannonicalName, "/")
		for _, p := range pathList {
			node = node.Children[p]
			if node == nil {
				return nil, fmt.Errorf("Asset %s not found", name)
			}
		}
	}
	if node.Func != nil {
		return nil, fmt.Errorf("Asset %s not found", name)
	}
	rv := make([]string, 0, len(node.Children))
	for childName := range node.Children {
		rv = append(rv, childName)
	}
	return rv, nil
}

type bintree struct {
	Func     func() (*asset, error)
	Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
	"datapath": &bintree{nil, map[string]*bintree{
		"bpf.o": &bintree{datapathBpfO, map[string]*bintree{}},
	}},
}}

func RestoreAsset(dir, name string) error {
	data, err := Asset(name)
	if err != nil {
		return err
	}
	info, err := AssetInfo(name)
	if err != nil {
		return err
	}
	err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
	if err != nil {
		return err
	}
	err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
	if err != nil {
		return err
	}
	return nil
}

func RestoreAssets(dir, name string) error {
	children, err := AssetDir(name)

	if err != nil {
		return RestoreAsset(dir, name)
	}

	for _, child := range children {
		err = RestoreAssets(dir, filepath.Join(name, child))
		if err != nil {
			return err
		}
	}
	return nil
}

func _filePath(dir, name string) string {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
// Code generated by go-bindata.
// sources:
// datapath/bpf.o
// DO NOT EDIT!

package cgroupbpf

import (
	"bytes"
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"time"
)

func bindataRead(data []byte, name string) ([]byte, error) {
	gz, err := gzip.NewReader(bytes.NewBuffer(data))
	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}

	var buf bytes.Buffer
	_, err = io.Copy(&buf, gz)
	clErr := gz.Close()

	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}
	if clErr != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}

type asset struct {
	bytes []byte
	info  os.FileInfo
}

type bindataFileInfo struct {
	name    string
	size    int64
	mode    os.FileMode
	modTime time.Time
}

func (fi bindataFileInfo) Name() string {
	return fi.name
}
func (fi bindataFileInfo) Size() int64 {
	return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
	return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
	return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
	return false
}
func (fi bindataFileInfo) Sys() interface{} {
	return nil
}

var _datapathBpfO = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x53\xcf\x8a\xd3\x40\x1c\xfe\x26\xc9\xa6\xd9\x5d\x0f\xab\x74\x65\x29\x8b\xf4\x22\xde\xb2\x95\xc5\xa3\xb0\xac\xa8\x07\x7b\x58\x14\x11\x44\x88\x69\x98\xd6\x6a\xa2\x69\x12\x41\x45\xd0\x83\x05\x5f\xc0\x07\x50\x41\x7c\x83\x1c\xdb\xa3\x8f\xd1\x83\x87\x1e\xf5\xa4\xb7\x91\x4c\x7e\xd3\x86\x69\x4a\xfd\x41\xe6\xcb\xf7\xf1\xfb\xcf\xcc\xbb\x9b\xdd\x5b\x06\x63\x50\xc6\xf0\x07\x4b\xb6\xb4\xef\xc6\xf2\xff\x84\xce\x1d\x30\xf8\x17\x1f\x49\x76\xdf\xde\x91\x98\xdb\xa5\xcf\xe4\x6b\x89\x0d\x13\x98\x0b\x21\x72\x8a\xcf\x2d\xa0\x09\x60\x0c\xa0\x05\x60\xf4\x79\x2e\x0a\xfd\x01\x03\x7e\x15\x79\x18\x93\xf9\xfd\x6f\x7f\xa5\x1e\x3c\xfd\x29\x31\x67\x40\xbb\xe0\xad\x99\xe4\x93\x2f\x94\xdf\x00\x66\x42\x88\x03\xad\xe9\xb1\x9c\x05\x98\x90\x9e\x13\xdf\xa7\x59\x73\xf2\xfb\x44\xb8\x0b\xc0\x01\x60\x01\x78\xff\xe1\x92\xf4\xbd\x7d\xd6\xc5\x9e\xda\xcb\x9b\xbb\x70\xde\xee\xb2\x73\x00\x0e\xe8\x53\xf6\xa3\x66\x5f\xba\x5d\x97\xb9\x7f\x0b\x5d\x7f\x28\x4f\x13\x8f\x35\xfd\x1e\xe9\xd3\x9a\x5c\x26\xcc\x15\xed\x32\x80\xf3\xb0\x17\xdc\x22\x6c\x00\xb8\x50\xf1\x57\xbd\xb6\xa4\xff\xd6\x42\x6f\x12\x7e\x24\x64\x14\x7b\x58\xe1\x32\xa7\x9b\xf1\x57\x19\xfa\xc3\x30\xe3\x89\xc7\x07\x09\x4f\x53\x44\x7e\x9c\x22\x8c\x23\xaf\x94\xe1\x79\xe1\x30\xe0\xcf\x53\x0e\x37\xe1\xa1\xcb\x9f\x78\xfd\xc4\x8f\x38\x7a\x71\xdf\x0d\xe0\xa6\x59\x92\xf9\x3d\xb8\xe9\xeb\xa8\xc0\xee\xe9\x69\xc7\xbb\x56\xc2\xb1\x8c\x08\x06\xc9\x8b\x97\xf1\x51\xfa\xac\x77\x75\xe3\x62\xff\xd3\x6e\xc8\xbd\xad\x5a\x87\xee\xe5\x48\xd3\xf5\x37\xc0\xe8\xb3\x35\xfd\x64\x4d\x3d\x4b\xe3\x7c\x43\xbc\x7e\x87\x1c\x8d\xfb\x00\xb6\x6b\xea\xec\x51\xff\xea\x9e\x6e\xd3\x9c\x2a\x5e\xe9\xfb\x54\x5f\xdf\x81\x43\x83\x36\x37\xf4\x7f\x65\x4d\xfc\x21\xab\xf7\xd7\xf7\x77\x4c\x9a\xa1\xe9\x6d\x72\xec\xe8\x7d\x69\xfc\x68\xcd\xfc\xed\x9a\xf9\x1b\x35\xf3\xdf\xa9\xa9\x5d\xd8\x19\xd5\x9f\x56\xfa\xde\xaa\xc4\xab\x77\xfe\x2f\x00\x00\xff\xff\xe2\x19\x8e\xe6\x28\x05\x00\x00")

func datapathBpfOBytes() ([]byte, error) {
	return bindataRead(
		_datapathBpfO,
		"datapath/bpf.o",
	)
}

func datapathBpfO() (*asset, error) {
	bytes, err := datapathBpfOBytes()
	if err != nil {
		return nil, err
	}

	info := bindataFileInfo{name: "datapath/bpf.o", size: 1320, mode: os.FileMode(436), modTime: time.Unix(1, 0)}
	a := &asset{bytes: bytes, info: info}
	return a, nil
}

// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	if f, ok := _bindata[cannonicalName]; ok {
		a, err := f()
		if err != nil {
			return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
		}
		return a.bytes, nil
	}
	return nil, fmt.Errorf("Asset %s not found", name)
}

// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
	a, err := Asset(name)
	if err != nil {
		panic("asset: Asset(" + name + "): " + err.Error())
	}

	return a
}

// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	if f, ok := _bindata[cannonicalName]; ok {
		a, err := f()
		if err != nil {
			return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
		}
		return a.info, nil
	}
	return nil, fmt.Errorf("AssetInfo %s not found", name)
}

// AssetNames returns the names of the assets.
func AssetNames() []string {
	names := make([]string, 0, len(_bindata))
	for name := range _bindata {
		names = append(names, name)
	}
	return names
}

// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
	"datapath/bpf.o": datapathBpfO,
}

// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
//     data/
//       foo.txt
//       img/
//         a.png
//         b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
	node := _bintree
	if len(name) != 0 {
		cannonicalName := strings.Replace(name, "\\", "/", -1)
		pathList := strings.Split(cannonicalName, "/")
		for _, p := range pathList {
			node = node.Children[p]
			if node == nil {
				return nil, fmt.Errorf("Asset %s not found", name)
			}
		}
	}
	if node.Func != nil {
		return nil, fmt.Errorf("Asset %s not found", name)
	}
	rv := make([]string, 0, len(node.Children))
	for childName := range node.Children {
		rv = append(rv, childName)
	}
	return rv, nil
}

type bintree struct {
	Func     func() (*asset, error)
	Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
	"datapath": &bintree{nil, map[string]*bintree{
		"bpf.o": &bintree{datapathBpfO, map[string]*bintree{}},
	}},
}}

// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
	data, err := Asset(name)
	if err != nil {
		return err
	}
	info, err := AssetInfo(name)
	if err != nil {
		return err
	}
	err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
	if err != nil {
		return err
	}
	err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
	if err != nil {
		return err
	}
	return nil
}

// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
	children, err := AssetDir(name)
	// File
	if err != nil {
		return RestoreAsset(dir, name)
	}
	// Dir
	for _, child := range children {
		err = RestoreAssets(dir, filepath.Join(name, child))
		if err != nil {
			return err
		}
	}
	return nil
}

func _filePath(dir, name string) string {
	cannonicalName := strings.Replace(name, "\\", "/", -1)
	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

