diff --git a/ls.go b/ls.go index fda6a02c..04c37243 100644 --- a/ls.go +++ b/ls.go @@ -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 { diff --git a/pkg/client/errors.go b/pkg/client/errors.go index cf0c016c..e73e23af 100644 --- a/pkg/client/errors.go +++ b/pkg/client/errors.go @@ -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{} diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index 7dc6ead0..570ccd69 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -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 } } diff --git a/sorted-list.go b/sorted-list.go index ce0c432c..4ab42abe 100644 --- a/sorted-list.go +++ b/sorted-list.go @@ -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