-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1511 from harshavardhana/fs-client-new
fs: More changes related to symlink handling.
- Loading branch information
Showing
2 changed files
with
110 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Minio Client (C) 2015 Minio, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this fs except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fs | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/minio/mc/pkg/client" | ||
"github.com/minio/minio-xl/pkg/probe" | ||
) | ||
|
||
// toClientError error constructs a typed client error for known filesystem errors. | ||
func (f *fsClient) toClientError(e error, fpath string) *probe.Error { | ||
if os.IsPermission(e) { | ||
return probe.NewError(client.PathInsufficientPermission{Path: fpath}) | ||
} | ||
if os.IsNotExist(e) { | ||
return probe.NewError(client.PathNotFound{Path: fpath}) | ||
} | ||
return probe.NewError(e) | ||
} | ||
|
||
// handle windows symlinks - eg: junction files. | ||
func (f *fsClient) handleWindowsSymlinks(fpath string) (os.FileInfo, *probe.Error) { | ||
// On windows there are directory symlinks which are called junction files. | ||
// These files carry special meaning on windows they cannot be, | ||
// accessed with regular operations. | ||
file, e := os.Lstat(fpath) | ||
if e != nil { | ||
err := f.toClientError(e, fpath) | ||
return nil, err.Trace(fpath) | ||
} | ||
return file, nil | ||
} | ||
|
||
// fsStat - wrapper function to get file stat. | ||
func (f *fsClient) fsStat() (os.FileInfo, *probe.Error) { | ||
fpath := f.PathURL.Path | ||
// Golang strips trailing / if you clean(..) or | ||
// EvalSymlinks(..). Adding '.' prevents it from doing so. | ||
if strings.HasSuffix(fpath, string(f.PathURL.Separator)) { | ||
fpath = fpath + "." | ||
} | ||
fpath, e := filepath.EvalSymlinks(fpath) | ||
if e != nil { | ||
if os.IsPermission(e) { | ||
if runtime.GOOS == "windows" { | ||
return f.handleWindowsSymlinks(fpath) | ||
} | ||
return nil, probe.NewError(client.PathInsufficientPermission{Path: fpath}) | ||
} | ||
err := f.toClientError(e, fpath) | ||
return nil, err.Trace(fpath) | ||
} | ||
st, e := os.Stat(fpath) | ||
if e != nil { | ||
if os.IsPermission(e) { | ||
if runtime.GOOS == "windows" { | ||
return f.handleWindowsSymlinks(fpath) | ||
} | ||
return nil, probe.NewError(client.PathInsufficientPermission{Path: f.PathURL.Path}) | ||
} | ||
if os.IsNotExist(e) { | ||
return nil, probe.NewError(client.PathNotFound{Path: f.PathURL.Path}) | ||
} | ||
return nil, probe.NewError(e) | ||
} | ||
return st, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters