1 // Copyright © 2014 Steve Francia <spf@spf13.com>.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
31 func (d httpDir) Open(name string) (http.File, error) {
32 if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 ||
33 strings.Contains(name, "\x00") {
34 return nil, errors.New("http: invalid character in file path")
36 dir := string(d.basePath)
41 f, err := d.fs.Open(filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))))
52 func NewHttpFs(source Fs) *HttpFs {
53 return &HttpFs{source: source}
56 func (h HttpFs) Dir(s string) *httpDir {
57 return &httpDir{basePath: s, fs: h}
60 func (h HttpFs) Name() string { return "h HttpFs" }
62 func (h HttpFs) Create(name string) (File, error) {
63 return h.source.Create(name)
66 func (h HttpFs) Chmod(name string, mode os.FileMode) error {
67 return h.source.Chmod(name, mode)
70 func (h HttpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
71 return h.source.Chtimes(name, atime, mtime)
74 func (h HttpFs) Mkdir(name string, perm os.FileMode) error {
75 return h.source.Mkdir(name, perm)
78 func (h HttpFs) MkdirAll(path string, perm os.FileMode) error {
79 return h.source.MkdirAll(path, perm)
82 func (h HttpFs) Open(name string) (http.File, error) {
83 f, err := h.source.Open(name)
85 if httpfile, ok := f.(http.File); ok {
92 func (h HttpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
93 return h.source.OpenFile(name, flag, perm)
96 func (h HttpFs) Remove(name string) error {
97 return h.source.Remove(name)
100 func (h HttpFs) RemoveAll(path string) error {
101 return h.source.RemoveAll(path)
104 func (h HttpFs) Rename(oldname, newname string) error {
105 return h.source.Rename(oldname, newname)
108 func (h HttpFs) Stat(name string) (os.FileInfo, error) {
109 return h.source.Stat(name)