2016-11-24 12:07:14 +00:00
|
|
|
// Copyright (C) 2016 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-11-24 12:07:14 +00:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2017-04-01 09:04:11 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-11-24 12:07:14 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The Filesystem interface abstracts access to the file system.
|
|
|
|
type Filesystem interface {
|
|
|
|
Chmod(name string, mode FileMode) error
|
|
|
|
Chtimes(name string, atime time.Time, mtime time.Time) error
|
|
|
|
Create(name string) (File, error)
|
2017-02-07 08:34:24 +00:00
|
|
|
CreateSymlink(name, target string) error
|
2016-11-24 12:07:14 +00:00
|
|
|
DirNames(name string) ([]string, error)
|
|
|
|
Lstat(name string) (FileInfo, error)
|
|
|
|
Mkdir(name string, perm FileMode) error
|
|
|
|
Open(name string) (File, error)
|
2017-02-07 08:34:24 +00:00
|
|
|
ReadSymlink(name string) (string, error)
|
2016-11-24 12:07:14 +00:00
|
|
|
Remove(name string) error
|
|
|
|
Rename(oldname, newname string) error
|
|
|
|
Stat(name string) (FileInfo, error)
|
|
|
|
SymlinksSupported() bool
|
|
|
|
Walk(root string, walkFn WalkFunc) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// The File interface abstracts access to a regular file, being a somewhat
|
|
|
|
// smaller interface than os.File
|
|
|
|
type File interface {
|
|
|
|
io.Reader
|
|
|
|
io.WriterAt
|
|
|
|
io.Closer
|
|
|
|
Truncate(size int64) error
|
2017-04-01 09:04:11 +00:00
|
|
|
Stat() (FileInfo, error)
|
2016-11-24 12:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The FileInfo interface is almost the same as os.FileInfo, but with the
|
|
|
|
// Sys method removed (as we don't want to expose whatever is underlying)
|
|
|
|
// and with a couple of convenience methods added.
|
|
|
|
type FileInfo interface {
|
|
|
|
// Standard things present in os.FileInfo
|
|
|
|
Name() string
|
|
|
|
Mode() FileMode
|
|
|
|
Size() int64
|
|
|
|
ModTime() time.Time
|
|
|
|
IsDir() bool
|
|
|
|
// Extensions
|
|
|
|
IsRegular() bool
|
|
|
|
IsSymlink() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// FileMode is similar to os.FileMode
|
|
|
|
type FileMode uint32
|
|
|
|
|
2017-04-01 09:04:11 +00:00
|
|
|
// ModePerm is the equivalent of os.ModePerm
|
|
|
|
const ModePerm = FileMode(os.ModePerm)
|
|
|
|
|
2016-11-24 12:07:14 +00:00
|
|
|
// DefaultFilesystem is the fallback to use when nothing explicitly has
|
|
|
|
// been passed.
|
2017-04-26 00:15:23 +00:00
|
|
|
var DefaultFilesystem Filesystem = NewWalkFilesystem(NewBasicFilesystem())
|
2016-11-24 12:07:14 +00:00
|
|
|
|
|
|
|
// SkipDir is used as a return value from WalkFuncs to indicate that
|
|
|
|
// the directory named in the call is to be skipped. It is not returned
|
|
|
|
// as an error by any function.
|
2017-04-01 09:04:11 +00:00
|
|
|
var SkipDir = filepath.SkipDir
|
|
|
|
|
|
|
|
// IsExist is the equivalent of os.IsExist
|
|
|
|
var IsExist = os.IsExist
|
|
|
|
|
|
|
|
// IsNotExist is the equivalent of os.IsNotExist
|
|
|
|
var IsNotExist = os.IsNotExist
|