Home Download Docs Code Community
     1	/*
     2	Copyright 2018 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	package files
    18	
    19	import (
    20		"os"
    21	)
    22	
    23	// OSFS returns an implementation of VFS interface using the host filesystem.
    24	func OSFS() VFS {
    25		return osFS{}
    26	}
    27	
    28	// osFS implements the VFS interface using the os package and
    29	// the host filesystem.
    30	type osFS struct{}
    31	
    32	func (osFS) Remove(path string) error                     { return os.Remove(path) }
    33	func (osFS) RemoveDir(path string) error                  { return os.Remove(path) }
    34	func (osFS) Stat(path string) (os.FileInfo, error)        { return os.Stat(path) }
    35	func (osFS) Lstat(path string) (os.FileInfo, error)       { return os.Lstat(path) }
    36	func (osFS) Open(path string) (ReadableFile, error)       { return os.Open(path) }
    37	func (osFS) MkdirAll(path string, perm os.FileMode) error { return os.MkdirAll(path, perm) }
    38	
    39	func (osFS) Rename(oldname, newname string) error {
    40		err := os.Rename(oldname, newname)
    41		if err != nil {
    42			err = mapRenameError(err, oldname, newname)
    43		}
    44		return err
    45	}
    46	
    47	func (osFS) TempFile(dir, prefix string) (WritableFile, error) {
    48		f, err := os.CreateTemp(dir, prefix)
    49		if err != nil {
    50			return nil, err
    51		}
    52		return f, nil
    53	}
    54	
    55	func (osFS) ReadDirNames(dir string) ([]string, error) {
    56		d, err := os.Open(dir)
    57		if err != nil {
    58			return nil, err
    59		}
    60		defer d.Close()
    61		return d.Readdirnames(-1)
    62	}
Website layout inspired by memcached.
Content by the authors.