Merge pull request #1170 from vadmeste/process_symlink_loop_error

Relax `too many levels symlink error` when traversing folders/files
This commit is contained in:
Harshavardhana
2015-10-08 15:15:33 -07:00
4 changed files with 29 additions and 21 deletions
+4 -1
View File
@@ -114,9 +114,12 @@ func doList(clnt client.Client, recursive, multipleArgs bool) *probe.Error {
if contentCh.Err != nil {
switch contentCh.Err.ToGoError().(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
case client.BrokenSymlink:
errorIf(contentCh.Err.Trace(), "Unable to list broken link.")
continue
case client.TooManyLevelsSymlink:
errorIf(contentCh.Err.Trace(), "Unable to list too many levels link.")
continue
}
if os.IsNotExist(contentCh.Err.ToGoError()) || os.IsPermission(contentCh.Err.ToGoError()) {
if contentCh.Content != nil {
+10 -17
View File
@@ -150,27 +150,20 @@ func (e NotFound) Error() string {
return "Requested file ‘" + e.Path + "’ not found"
}
// ISFolder (EISDIR) - accessed file is a folder
type ISFolder GenericFileError
// BrokenSymlink (ENOTENT) - file has broken symlink
type BrokenSymlink GenericFileError
func (e ISFolder) Error() string {
return "Requested file ‘" + e.Path + "’ is a folder"
}
// NotFolder (ENOTDIR) - accessed file is not a folder
type NotFolder GenericFileError
func (e NotFolder) Error() string {
return "Requested file ‘" + e.Path + "’ is not a folder"
}
// ISBrokenSymlink (ENOTENT) - file has broken symlink
type ISBrokenSymlink GenericFileError
func (e ISBrokenSymlink) Error() string {
func (e BrokenSymlink) Error() string {
return "Requested file ‘" + e.Path + "’ has broken symlink"
}
// TooManyLevelsSymlink (ELOOP) - file has too many levels of symlinks
type TooManyLevelsSymlink GenericFileError
func (e TooManyLevelsSymlink) Error() string {
return "Requested file ‘" + e.Path + "’ has too many levels of symlinks"
}
// EmptyPath (EINVAL) - invalid argument
type EmptyPath struct{}
+10 -2
View File
@@ -286,7 +286,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
if os.IsNotExist(err) {
contentCh <- client.ContentOnChannel{
Content: nil,
Err: probe.NewError(client.ISBrokenSymlink{Path: file.Name()}),
Err: probe.NewError(client.BrokenSymlink{Path: file.Name()}),
}
continue
}
@@ -416,10 +416,18 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
if os.IsNotExist(err) { // ignore broken symlinks
contentCh <- client.ContentOnChannel{
Content: nil,
Err: probe.NewError(client.ISBrokenSymlink{Path: fp}),
Err: probe.NewError(client.BrokenSymlink{Path: fp}),
}
return nil
}
if strings.Contains(err.Error(), "too many levels of symbolic links") {
contentCh <- client.ContentOnChannel{
Content: nil,
Err: probe.NewError(client.TooManyLevelsSymlink{Path: fp}),
}
return nil
}
return err
}
}
+5 -1
View File
@@ -79,10 +79,14 @@ func (sl *sortedList) Create(clnt client.Client, id string) *probe.Error {
for content := range clnt.List(true) {
if content.Err != nil {
switch err := content.Err.ToGoError().(type) {
case client.ISBrokenSymlink:
case client.BrokenSymlink:
// FIXME: send the error to caller using channel
errorIf(content.Err.Trace(), fmt.Sprintf("Skipping broken Symlink ‘%s’.", err.Path))
continue
case client.TooManyLevelsSymlink:
// FIXME: send the error to caller using channel
errorIf(content.Err.Trace(), fmt.Sprintf("Skipping too many levels Symlink ‘%s’.", err.Path))
continue
}
if os.IsNotExist(content.Err.ToGoError()) || os.IsPermission(content.Err.ToGoError()) {
// FIXME: abstract this at fs.go layer