mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
lib/fs: Rename fsFile* to basicFile* (#5546)
This commit is contained in:
parent
4b8853bfde
commit
ad5a046843
@ -144,7 +144,7 @@ func (f *BasicFilesystem) Lstat(name string) (FileInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFileInfo{fi}, err
|
||||
return basicFileInfo{fi}, err
|
||||
}
|
||||
|
||||
func (f *BasicFilesystem) Remove(name string) error {
|
||||
@ -184,7 +184,7 @@ func (f *BasicFilesystem) Stat(name string) (FileInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFileInfo{fi}, err
|
||||
return basicFileInfo{fi}, err
|
||||
}
|
||||
|
||||
func (f *BasicFilesystem) DirNames(name string) ([]string, error) {
|
||||
@ -215,7 +215,7 @@ func (f *BasicFilesystem) Open(name string) (File, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFile{fd, name}, err
|
||||
return basicFile{fd, name}, err
|
||||
}
|
||||
|
||||
func (f *BasicFilesystem) OpenFile(name string, flags int, mode FileMode) (File, error) {
|
||||
@ -227,7 +227,7 @@ func (f *BasicFilesystem) OpenFile(name string, flags int, mode FileMode) (File,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFile{fd, name}, err
|
||||
return basicFile{fd, name}, err
|
||||
}
|
||||
|
||||
func (f *BasicFilesystem) Create(name string) (File, error) {
|
||||
@ -239,7 +239,7 @@ func (f *BasicFilesystem) Create(name string) (File, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFile{fd, name}, err
|
||||
return basicFile{fd, name}, err
|
||||
}
|
||||
|
||||
func (f *BasicFilesystem) Walk(root string, walkFn WalkFunc) error {
|
||||
@ -283,8 +283,8 @@ func (f *BasicFilesystem) URI() string {
|
||||
func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
|
||||
// Like os.SameFile, we always return false unless fi1 and fi2 were created
|
||||
// by this package's Stat/Lstat method.
|
||||
f1, ok1 := fi1.(fsFileInfo)
|
||||
f2, ok2 := fi2.(fsFileInfo)
|
||||
f1, ok1 := fi1.(basicFileInfo)
|
||||
f2, ok2 := fi2.(basicFileInfo)
|
||||
if !ok1 || !ok2 {
|
||||
return false
|
||||
}
|
||||
@ -292,36 +292,36 @@ func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
|
||||
return os.SameFile(f1.FileInfo, f2.FileInfo)
|
||||
}
|
||||
|
||||
// fsFile implements the fs.File interface on top of an os.File
|
||||
type fsFile struct {
|
||||
// basicFile implements the fs.File interface on top of an os.File
|
||||
type basicFile struct {
|
||||
*os.File
|
||||
name string
|
||||
}
|
||||
|
||||
func (f fsFile) Name() string {
|
||||
func (f basicFile) Name() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
func (f fsFile) Stat() (FileInfo, error) {
|
||||
func (f basicFile) Stat() (FileInfo, error) {
|
||||
info, err := f.File.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fsFileInfo{info}, nil
|
||||
return basicFileInfo{info}, nil
|
||||
}
|
||||
|
||||
// fsFileInfo implements the fs.FileInfo interface on top of an os.FileInfo.
|
||||
type fsFileInfo struct {
|
||||
// basicFileInfo implements the fs.FileInfo interface on top of an os.FileInfo.
|
||||
type basicFileInfo struct {
|
||||
os.FileInfo
|
||||
}
|
||||
|
||||
func (e fsFileInfo) IsSymlink() bool {
|
||||
// Must use fsFileInfo.Mode() because it may apply magic.
|
||||
func (e basicFileInfo) IsSymlink() bool {
|
||||
// Must use basicFileInfo.Mode() because it may apply magic.
|
||||
return e.Mode()&ModeSymlink != 0
|
||||
}
|
||||
|
||||
func (e fsFileInfo) IsRegular() bool {
|
||||
// Must use fsFileInfo.Mode() because it may apply magic.
|
||||
func (e basicFileInfo) IsRegular() bool {
|
||||
// Must use basicFileInfo.Mode() because it may apply magic.
|
||||
return e.Mode()&ModeType == 0
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2019 The Syncthing Authors.
|
||||
// Copyright (C) 2017 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,
|
||||
@ -10,14 +10,18 @@ package fs
|
||||
|
||||
import "syscall"
|
||||
|
||||
func (e fsFileInfo) Owner() int {
|
||||
func (e basicFileInfo) Mode() FileMode {
|
||||
return FileMode(e.FileInfo.Mode())
|
||||
}
|
||||
|
||||
func (e basicFileInfo) Owner() int {
|
||||
if st, ok := e.Sys().(*syscall.Stat_t); ok {
|
||||
return int(st.Uid)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (e fsFileInfo) Group() int {
|
||||
func (e basicFileInfo) Group() int {
|
||||
if st, ok := e.Sys().(*syscall.Stat_t); ok {
|
||||
return int(st.Gid)
|
||||
}
|
@ -30,7 +30,7 @@ func isWindowsExecutable(path string) bool {
|
||||
return execExts[strings.ToLower(filepath.Ext(path))]
|
||||
}
|
||||
|
||||
func (e fsFileInfo) Mode() FileMode {
|
||||
func (e basicFileInfo) Mode() FileMode {
|
||||
m := e.FileInfo.Mode()
|
||||
if m&os.ModeSymlink != 0 && e.Size() > 0 {
|
||||
// "Symlinks" with nonzero size are in fact "hard" links, such as
|
||||
@ -48,3 +48,11 @@ func (e fsFileInfo) Mode() FileMode {
|
||||
m &^= 0022
|
||||
return FileMode(m)
|
||||
}
|
||||
|
||||
func (e basicFileInfo) Owner() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (e basicFileInfo) Group() int {
|
||||
return -1
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright (C) 2019 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,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package fs
|
||||
|
||||
func (e fsFileInfo) Owner() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (e fsFileInfo) Group() int {
|
||||
return -1
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright (C) 2017 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,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package fs
|
||||
|
||||
func (e fsFileInfo) Mode() FileMode {
|
||||
return FileMode(e.FileInfo.Mode())
|
||||
}
|
Loading…
Reference in New Issue
Block a user