<commit_before>/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import (
	"path"
	"errors"
	"os"
	"strings"
	"k8s.io/kops/util/pkg/vfs"
)

var ReadOnlyError = errors.New("AssetPath is read-only")

type AssetPath struct {
	location string
}

var _ vfs.Path = &AssetPath{}

func NewAssetPath(location string) *AssetPath {
	a := &AssetPath{
		location: location,
	}
	return a
}

func (p *AssetPath) Join(relativePath ...string) vfs.Path {
	args := []string{p.location}
	args = append(args, relativePath...)
	joined := path.Join(args...)
	return &AssetPath{location: joined}
}

func (p *AssetPath) WriteFile(data []byte) error {
	return ReadOnlyError
}

func (p *AssetPath) CreateFile(data []byte) error {
	return ReadOnlyError
}

func (p *AssetPath) ReadFile() ([]byte, error) {
	data, err := Asset(p.location)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return nil, os.ErrNotExist
		}
	}
	return data, err
}

func (p *AssetPath) ReadDir() ([]vfs.Path, error) {
	files, err := AssetDir(p.location)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return nil, os.ErrNotExist
		}
		return nil, err
	}
	var paths []vfs.Path
	for _, f := range files {
		paths = append(paths, NewAssetPath(path.Join(p.location, f)))
	}
	return paths, nil
}

func (p *AssetPath) ReadTree() ([]vfs.Path, error) {
	var paths []vfs.Path
	err := readTree(p.location, &paths)
	if err != nil {
		return nil, err
	}
	return paths, nil
}

func readTree(base string, dest *[]vfs.Path) error {
	files, err := AssetDir(base)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return os.ErrNotExist
		}
		return err
	}
	for _, f := range files {
		p := path.Join(base, f)
		*dest = append(*dest, NewAssetPath(p))

		// We always assume a directory, but ignore if not found
		// This is because go-bindata doesn't support FileInfo on directories :-(
		{
			err = readTree(p, dest)
			if err != nil && !os.IsNotExist(err){
				return err
			}
		}
	}
	return nil
}

func (p *AssetPath) Base() string {
	return path.Base(p.location)
}

func (p *AssetPath) Path() string {<commit_msg>for whatever reason the import was missing for asset, which caused compile failures for api and examples<commit_after>/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import (
	"errors"
	"os"
	"path"
	"strings"

	_ "github.com/google/cadvisor/pages/static"

	"k8s.io/kops/util/pkg/vfs"
)

var ReadOnlyError = errors.New("AssetPath is read-only")

type AssetPath struct {
	location string
}

var _ vfs.Path = &AssetPath{}

func NewAssetPath(location string) *AssetPath {
	a := &AssetPath{
		location: location,
	}
	return a
}

func (p *AssetPath) Join(relativePath ...string) vfs.Path {
	args := []string{p.location}
	args = append(args, relativePath...)
	joined := path.Join(args...)
	return &AssetPath{location: joined}
}

func (p *AssetPath) WriteFile(data []byte) error {
	return ReadOnlyError
}

func (p *AssetPath) CreateFile(data []byte) error {
	return ReadOnlyError
}

func (p *AssetPath) ReadFile() ([]byte, error) {
	data, err := Asset(p.location)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return nil, os.ErrNotExist
		}
	}
	return data, err
}

func (p *AssetPath) ReadDir() ([]vfs.Path, error) {
	files, err := AssetDir(p.location)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return nil, os.ErrNotExist
		}
		return nil, err
	}
	var paths []vfs.Path
	for _, f := range files {
		paths = append(paths, NewAssetPath(path.Join(p.location, f)))
	}
	return paths, nil
}

func (p *AssetPath) ReadTree() ([]vfs.Path, error) {
	var paths []vfs.Path
	err := readTree(p.location, &paths)
	if err != nil {
		return nil, err
	}
	return paths, nil
}

func readTree(base string, dest *[]vfs.Path) error {
	files, err := AssetDir(base)
	if err != nil {
		// Yuk
		if strings.Contains(err.Error(), "not found") {
			return os.ErrNotExist
		}
		return err
	}
	for _, f := range files {
		p := path.Join(base, f)
		*dest = append(*dest, NewAssetPath(p))

		// We always assume a directory, but ignore if not found
		// This is because go-bindata doesn't support FileInfo on directories :-(
		{
			err = readTree(p, dest)
			if err != nil && !os.IsNotExist(err) {
				return err
			}
		}
	}
	return nil
}

func (p *AssetPath) Base() string {
	return path.Base(p.location)
}

func (p *AssetPath) Path() string {
{'fraction_non_alphanumeric': 0.12907930720145852, 'fraction_numerical': 0.0032816773017319964, 'mean_word_length': 3.6969178082191783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '723212', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1855, 'n_words': 619}