mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
windows: Support all REPARSE_POINT attrib files properly. (#4203)
This change adopts the upstream fix in this regard at https://go-review.googlesource.com/#/c/41834/ for Minio's purposes. Go's current os.Stat() lacks support for lot of strange windows files such as - share symlinks on SMB2 - symlinks on docker nanoserver - de-duplicated files on NTFS de-duplicated volume. This PR attempts to incorporate the change mentioned here https://blogs.msdn.microsoft.com/oldnewthing/20100212-00/?p=14963/ The article suggests to use Windows I/O manager to dereference the symbolic link. Fixes #4122
This commit is contained in:
@@ -45,7 +45,7 @@ func TestServerConfigMigrateV1(t *testing.T) {
|
||||
t.Fatal("Unexpected error: ", err)
|
||||
}
|
||||
// Check if config v1 is removed from filesystem
|
||||
if _, err := os.Stat(configPath); err == nil || !os.IsNotExist(err) {
|
||||
if _, err := osStat(configPath); err == nil || !os.IsNotExist(err) {
|
||||
t.Fatal("Config V1 file is not purged")
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ func fsStatDir(statDir string) (os.FileInfo, error) {
|
||||
return nil, traceError(err)
|
||||
}
|
||||
|
||||
fi, err := os.Stat(preparePath(statDir))
|
||||
fi, err := osStat(preparePath(statDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, traceError(errVolumeNotFound)
|
||||
@@ -160,7 +160,7 @@ func fsStatFile(statFile string) (os.FileInfo, error) {
|
||||
return nil, traceError(err)
|
||||
}
|
||||
|
||||
fi, err := os.Stat(preparePath(statFile))
|
||||
fi, err := osStat(preparePath(statFile))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, traceError(errFileNotFound)
|
||||
@@ -206,7 +206,7 @@ func fsOpenFile(readPath string, offset int64) (io.ReadCloser, int64, error) {
|
||||
}
|
||||
|
||||
// Stat to get the size of the file at path.
|
||||
st, err := fr.Stat()
|
||||
st, err := osStat(preparePath(readPath))
|
||||
if err != nil {
|
||||
return nil, 0, traceError(err)
|
||||
}
|
||||
@@ -344,7 +344,7 @@ func fsDeleteFile(basePath, deletePath string) error {
|
||||
}
|
||||
|
||||
// Verify if the path exists.
|
||||
pathSt, err := os.Stat(preparePath(deletePath))
|
||||
pathSt, err := osStat(preparePath(deletePath))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return traceError(errFileNotFound)
|
||||
|
||||
@@ -442,11 +442,11 @@ func TestFSRemoveMeta(t *testing.T) {
|
||||
t.Fatalf("Unable to remove file, %s", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filePath); !os.IsNotExist(err) {
|
||||
if _, err := osStat(preparePath(filePath)); !os.IsNotExist(err) {
|
||||
t.Fatalf("`%s` file found though it should have been deleted.", filePath)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path.Dir(filePath)); !os.IsNotExist(err) {
|
||||
if _, err := osStat(preparePath(path.Dir(filePath))); !os.IsNotExist(err) {
|
||||
t.Fatalf("`%s` parent directory found though it should have been deleted.", filePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func newFSObjectLayer(fsPath string) (ObjectLayer, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fi, err := os.Stat(preparePath(fsPath))
|
||||
fi, err := osStat(preparePath(fsPath))
|
||||
if err == nil {
|
||||
if !fi.IsDir() {
|
||||
return nil, syscall.ENOTDIR
|
||||
@@ -224,7 +224,7 @@ func (fs fsObjects) GetBucketInfo(bucket string) (BucketInfo, error) {
|
||||
return BucketInfo{}, toObjectErr(err, bucket)
|
||||
}
|
||||
|
||||
// As os.Stat() doesn't carry other than ModTime(), use ModTime() as CreatedTime.
|
||||
// As osStat() doesn't carry other than ModTime(), use ModTime() as CreatedTime.
|
||||
createdTime := st.ModTime()
|
||||
return BucketInfo{
|
||||
Name: bucket,
|
||||
@@ -263,7 +263,7 @@ func (fs fsObjects) ListBuckets() ([]BucketInfo, error) {
|
||||
|
||||
bucketInfos = append(bucketInfos, BucketInfo{
|
||||
Name: fi.Name(),
|
||||
// As os.Stat() doesnt carry CreatedTime, use ModTime() as CreatedTime.
|
||||
// As osStat() doesnt carry CreatedTime, use ModTime() as CreatedTime.
|
||||
Created: fi.ModTime(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -75,12 +75,12 @@ func parseDirents(dirPath string, buf []byte) (entries []string, err error) {
|
||||
case syscall.DT_REG:
|
||||
entries = append(entries, name)
|
||||
case syscall.DT_LNK, syscall.DT_UNKNOWN:
|
||||
// If its symbolic link, follow the link using os.Stat()
|
||||
// If its symbolic link, follow the link using osStat()
|
||||
|
||||
// On Linux XFS does not implement d_type for on disk
|
||||
// format << v5. Fall back to Stat().
|
||||
// format << v5. Fall back to OsStat().
|
||||
var fi os.FileInfo
|
||||
fi, err = os.Stat(path.Join(dirPath, name))
|
||||
fi, err = osStat(path.Join(dirPath, name))
|
||||
if err != nil {
|
||||
// If file does not exist, we continue and skip it.
|
||||
// Could happen if it was deleted in the middle while
|
||||
|
||||
@@ -55,7 +55,7 @@ func readDir(dirPath string) (entries []string, err error) {
|
||||
// Stat symbolic link and follow to get the final value.
|
||||
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||
var st os.FileInfo
|
||||
st, err = os.Stat(preparePath(path.Join(dirPath, fi.Name())))
|
||||
st, err = osStat(preparePath(path.Join(dirPath, fi.Name())))
|
||||
if err != nil {
|
||||
errorIf(err, "Unable to stat path %s", path.Join(dirPath, fi.Name()))
|
||||
continue
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build linux darwin dragonfly freebsd netbsd openbsd solaris
|
||||
// +build !windows
|
||||
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
||||
@@ -20,6 +20,12 @@ package cmd
|
||||
|
||||
import "os"
|
||||
|
||||
// osStat returns a FileInfo structure describing the named file.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func osStat(name string) (os.FileInfo, error) {
|
||||
return os.Stat(name)
|
||||
}
|
||||
|
||||
// isValidVolname verifies a volname name in accordance with object
|
||||
// layer requirements.
|
||||
func isValidVolname(volname string) bool {
|
||||
|
||||
@@ -20,7 +20,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"syscall"
|
||||
"testing"
|
||||
@@ -62,7 +61,7 @@ func TestIsValidUmaskVol(t *testing.T) {
|
||||
defer removeAll(tmpPath)
|
||||
|
||||
// Stat to get permissions bits.
|
||||
st, err := os.Stat(path.Join(tmpPath, testCase.volName))
|
||||
st, err := osStat(path.Join(tmpPath, testCase.volName))
|
||||
if err != nil {
|
||||
t.Fatalf("Stat failed with %s expected to pass.", err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
* Minio Cloud Storage, (C) 2017 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,8 +24,15 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
os2 "github.com/minio/minio/pkg/x/os"
|
||||
)
|
||||
|
||||
// Wrapper around safe stat implementation to avoid windows bugs.
|
||||
func osStat(name string) (os.FileInfo, error) {
|
||||
return os2.Stat(name)
|
||||
}
|
||||
|
||||
// isValidVolname verifies a volname name in accordance with object
|
||||
// layer requirements.
|
||||
func isValidVolname(volname string) bool {
|
||||
@@ -44,7 +51,7 @@ func isValidVolname(volname string) bool {
|
||||
func mkdirAll(path string, perm os.FileMode) error {
|
||||
path = preparePath(path)
|
||||
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
|
||||
dir, err := os.Stat(path)
|
||||
dir, err := osStat(path)
|
||||
if err == nil {
|
||||
if dir.IsDir() {
|
||||
return nil
|
||||
|
||||
36
cmd/posix.go
36
cmd/posix.go
@@ -116,7 +116,7 @@ func newPosix(path string) (StorageAPI, error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
fi, err := os.Stat(preparePath(diskPath))
|
||||
fi, err := osStat(preparePath(diskPath))
|
||||
if err == nil {
|
||||
if !fi.IsDir() {
|
||||
return nil, syscall.ENOTDIR
|
||||
@@ -230,7 +230,7 @@ func (s *posix) getVolDir(volume string) (string, error) {
|
||||
// checkDiskFound - validates if disk is available,
|
||||
// returns errDiskNotFound if not found.
|
||||
func (s *posix) checkDiskFound() (err error) {
|
||||
_, err = os.Stat(preparePath(s.diskPath))
|
||||
_, err = osStat(preparePath(s.diskPath))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return errDiskNotFound
|
||||
@@ -321,7 +321,7 @@ func listVols(dirPath string) ([]VolInfo, error) {
|
||||
continue
|
||||
}
|
||||
var fi os.FileInfo
|
||||
fi, err = os.Stat(preparePath(pathJoin(dirPath, entry)))
|
||||
fi, err = osStat(preparePath(pathJoin(dirPath, entry)))
|
||||
if err != nil {
|
||||
// If the file does not exist, skip the entry.
|
||||
if os.IsNotExist(err) {
|
||||
@@ -331,7 +331,7 @@ func listVols(dirPath string) ([]VolInfo, error) {
|
||||
}
|
||||
volsInfo = append(volsInfo, VolInfo{
|
||||
Name: fi.Name(),
|
||||
// As os.Stat() doesn't carry other than ModTime(), use
|
||||
// As osStat() doesn't carry other than ModTime(), use
|
||||
// ModTime() as CreatedTime.
|
||||
Created: fi.ModTime(),
|
||||
})
|
||||
@@ -362,14 +362,14 @@ func (s *posix) StatVol(volume string) (volInfo VolInfo, err error) {
|
||||
}
|
||||
// Stat a volume entry.
|
||||
var st os.FileInfo
|
||||
st, err = os.Stat(preparePath(volumeDir))
|
||||
st, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return VolInfo{}, errVolumeNotFound
|
||||
}
|
||||
return VolInfo{}, err
|
||||
}
|
||||
// As os.Stat() doesn't carry other than ModTime(), use ModTime()
|
||||
// As osStat() doesn't carry other than ModTime(), use ModTime()
|
||||
// as CreatedTime.
|
||||
createdTime := st.ModTime()
|
||||
return VolInfo{
|
||||
@@ -434,7 +434,7 @@ func (s *posix) ListDir(volume, dirPath string) (entries []string, err error) {
|
||||
return nil, err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, errVolumeNotFound
|
||||
@@ -470,7 +470,7 @@ func (s *posix) ReadAll(volume, path string) (buf []byte, err error) {
|
||||
return nil, err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, errVolumeNotFound
|
||||
@@ -536,7 +536,7 @@ func (s *posix) ReadFile(volume string, path string, offset int64, buf []byte) (
|
||||
return 0, err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return 0, errVolumeNotFound
|
||||
@@ -609,7 +609,7 @@ func (s *posix) createFile(volume, path string) (f *os.File, err error) {
|
||||
return nil, err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, errVolumeNotFound
|
||||
@@ -624,7 +624,7 @@ func (s *posix) createFile(volume, path string) (f *os.File, err error) {
|
||||
|
||||
// Verify if the file already exists and is not of regular type.
|
||||
var st os.FileInfo
|
||||
if st, err = os.Stat(preparePath(filePath)); err == nil {
|
||||
if st, err = osStat(preparePath(filePath)); err == nil {
|
||||
if !st.Mode().IsRegular() {
|
||||
return nil, errIsNotRegular
|
||||
}
|
||||
@@ -760,7 +760,7 @@ func (s *posix) StatFile(volume, path string) (file FileInfo, err error) {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return FileInfo{}, errVolumeNotFound
|
||||
@@ -772,7 +772,7 @@ func (s *posix) StatFile(volume, path string) (file FileInfo, err error) {
|
||||
if err = checkPathLength(preparePath(filePath)); err != nil {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
st, err := os.Stat(preparePath(filePath))
|
||||
st, err := osStat(preparePath(filePath))
|
||||
if err != nil {
|
||||
// File is really not found.
|
||||
if os.IsNotExist(err) {
|
||||
@@ -806,7 +806,7 @@ func deleteFile(basePath, deletePath string) error {
|
||||
return nil
|
||||
}
|
||||
// Verify if the path exists.
|
||||
pathSt, err := os.Stat(preparePath(deletePath))
|
||||
pathSt, err := osStat(preparePath(deletePath))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return errFileNotFound
|
||||
@@ -856,7 +856,7 @@ func (s *posix) DeleteFile(volume, path string) (err error) {
|
||||
return err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(volumeDir))
|
||||
_, err = osStat(preparePath(volumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return errVolumeNotFound
|
||||
@@ -900,14 +900,14 @@ func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err e
|
||||
return err
|
||||
}
|
||||
// Stat a volume entry.
|
||||
_, err = os.Stat(preparePath(srcVolumeDir))
|
||||
_, err = osStat(preparePath(srcVolumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return errVolumeNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
_, err = os.Stat(preparePath(dstVolumeDir))
|
||||
_, err = osStat(preparePath(dstVolumeDir))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return errVolumeNotFound
|
||||
@@ -930,7 +930,7 @@ func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err e
|
||||
}
|
||||
if srcIsDir {
|
||||
// If source is a directory we expect the destination to be non-existent always.
|
||||
_, err = os.Stat(preparePath(dstFilePath))
|
||||
_, err = osStat(preparePath(dstFilePath))
|
||||
if err == nil {
|
||||
return errFileAccessDenied
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func getCurrentReleaseTime(minioVersion, minioBinaryPath string) (releaseTime ti
|
||||
}
|
||||
|
||||
// Looks like version is minio non-standard, we use minio binary's ModTime as release time.
|
||||
fi, err := os.Stat(minioBinaryPath)
|
||||
fi, err := osStat(minioBinaryPath)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Unable to get ModTime of %s. %s", minioBinaryPath, err)
|
||||
} else {
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestGetCurrentReleaseTime(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fi, err = os.Stat(goBinAbsPath)
|
||||
fi, err = osStat(goBinAbsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func TestGetCurrentReleaseTime(t *testing.T) {
|
||||
}
|
||||
errorMessage4 := "Unable to get ModTime of /tmp/non-existent-file. stat /tmp/non-existent-file: no such file or directory"
|
||||
if runtime.GOOS == "windows" {
|
||||
errorMessage4 = "Unable to get ModTime of C:\\tmp\\non-existent-file. GetFileAttributesEx C:\\tmp\\non-existent-file: The system cannot find the path specified."
|
||||
errorMessage4 = "Unable to get ModTime of C:\\tmp\\non-existent-file. CreateFile C:\\tmp\\non-existent-file: The system cannot find the path specified."
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -182,7 +181,7 @@ func dumpRequest(r *http.Request) string {
|
||||
|
||||
// isFile - returns whether given path is a file or not.
|
||||
func isFile(path string) bool {
|
||||
if fi, err := os.Stat(path); err == nil {
|
||||
if fi, err := osStat(path); err == nil {
|
||||
return fi.Mode().IsRegular()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user