lib/fs: Rename fsFile* to basicFile* (#5546)

This commit is contained in:
Simon Frei 2019-02-24 18:02:02 +01:00 committed by GitHub
parent 4b8853bfde
commit ad5a046843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 50 deletions

View File

@ -144,7 +144,7 @@ func (f *BasicFilesystem) Lstat(name string) (FileInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fsFileInfo{fi}, err return basicFileInfo{fi}, err
} }
func (f *BasicFilesystem) Remove(name string) error { func (f *BasicFilesystem) Remove(name string) error {
@ -184,7 +184,7 @@ func (f *BasicFilesystem) Stat(name string) (FileInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fsFileInfo{fi}, err return basicFileInfo{fi}, err
} }
func (f *BasicFilesystem) DirNames(name string) ([]string, error) { func (f *BasicFilesystem) DirNames(name string) ([]string, error) {
@ -215,7 +215,7 @@ func (f *BasicFilesystem) Open(name string) (File, error) {
if err != nil { if err != nil {
return nil, err 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) { 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 { if err != nil {
return nil, err return nil, err
} }
return fsFile{fd, name}, err return basicFile{fd, name}, err
} }
func (f *BasicFilesystem) Create(name string) (File, error) { func (f *BasicFilesystem) Create(name string) (File, error) {
@ -239,7 +239,7 @@ func (f *BasicFilesystem) Create(name string) (File, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fsFile{fd, name}, err return basicFile{fd, name}, err
} }
func (f *BasicFilesystem) Walk(root string, walkFn WalkFunc) error { 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 { func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
// Like os.SameFile, we always return false unless fi1 and fi2 were created // Like os.SameFile, we always return false unless fi1 and fi2 were created
// by this package's Stat/Lstat method. // by this package's Stat/Lstat method.
f1, ok1 := fi1.(fsFileInfo) f1, ok1 := fi1.(basicFileInfo)
f2, ok2 := fi2.(fsFileInfo) f2, ok2 := fi2.(basicFileInfo)
if !ok1 || !ok2 { if !ok1 || !ok2 {
return false return false
} }
@ -292,36 +292,36 @@ func (f *BasicFilesystem) SameFile(fi1, fi2 FileInfo) bool {
return os.SameFile(f1.FileInfo, f2.FileInfo) return os.SameFile(f1.FileInfo, f2.FileInfo)
} }
// fsFile implements the fs.File interface on top of an os.File // basicFile implements the fs.File interface on top of an os.File
type fsFile struct { type basicFile struct {
*os.File *os.File
name string name string
} }
func (f fsFile) Name() string { func (f basicFile) Name() string {
return f.name return f.name
} }
func (f fsFile) Stat() (FileInfo, error) { func (f basicFile) Stat() (FileInfo, error) {
info, err := f.File.Stat() info, err := f.File.Stat()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fsFileInfo{info}, nil return basicFileInfo{info}, nil
} }
// fsFileInfo implements the fs.FileInfo interface on top of an os.FileInfo. // basicFileInfo implements the fs.FileInfo interface on top of an os.FileInfo.
type fsFileInfo struct { type basicFileInfo struct {
os.FileInfo os.FileInfo
} }
func (e fsFileInfo) IsSymlink() bool { func (e basicFileInfo) IsSymlink() bool {
// Must use fsFileInfo.Mode() because it may apply magic. // Must use basicFileInfo.Mode() because it may apply magic.
return e.Mode()&ModeSymlink != 0 return e.Mode()&ModeSymlink != 0
} }
func (e fsFileInfo) IsRegular() bool { func (e basicFileInfo) IsRegular() bool {
// Must use fsFileInfo.Mode() because it may apply magic. // Must use basicFileInfo.Mode() because it may apply magic.
return e.Mode()&ModeType == 0 return e.Mode()&ModeType == 0
} }

View File

@ -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 // 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, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
@ -10,14 +10,18 @@ package fs
import "syscall" 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 { if st, ok := e.Sys().(*syscall.Stat_t); ok {
return int(st.Uid) return int(st.Uid)
} }
return -1 return -1
} }
func (e fsFileInfo) Group() int { func (e basicFileInfo) Group() int {
if st, ok := e.Sys().(*syscall.Stat_t); ok { if st, ok := e.Sys().(*syscall.Stat_t); ok {
return int(st.Gid) return int(st.Gid)
} }

View File

@ -30,7 +30,7 @@ func isWindowsExecutable(path string) bool {
return execExts[strings.ToLower(filepath.Ext(path))] return execExts[strings.ToLower(filepath.Ext(path))]
} }
func (e fsFileInfo) Mode() FileMode { func (e basicFileInfo) Mode() FileMode {
m := e.FileInfo.Mode() m := e.FileInfo.Mode()
if m&os.ModeSymlink != 0 && e.Size() > 0 { if m&os.ModeSymlink != 0 && e.Size() > 0 {
// "Symlinks" with nonzero size are in fact "hard" links, such as // "Symlinks" with nonzero size are in fact "hard" links, such as
@ -48,3 +48,11 @@ func (e fsFileInfo) Mode() FileMode {
m &^= 0022 m &^= 0022
return FileMode(m) return FileMode(m)
} }
func (e basicFileInfo) Owner() int {
return -1
}
func (e basicFileInfo) Group() int {
return -1
}

View File

@ -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
}

View File

@ -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())
}