Skip to content

Commit

Permalink
Merge pull request #116 from ross-spencer/master
Browse files Browse the repository at this point in the history
Ensure that SF doesn't hang w/o user read perms; resolves #113
  • Loading branch information
richardlehane committed May 25, 2018
2 parents 4738f91 + a3cf617 commit ea5300d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/sf/longpath.go
Expand Up @@ -55,6 +55,11 @@ func identify(ctxts chan *context, root, orig string, coerr, norecurse, droid bo
printFile(ctxts, gf(path, "", info.ModTime().Format(time.RFC3339), info.Size()), ModeError(info.Mode()))
return nil
}
// zero user read permissions mask, octal 400 (decimal 256)
if info.Mode()&(256) == 0 {
printFile(ctxts, gf(path, "", info.ModTime().Format(time.RFC3339), info.Size()), ModeError(info.Mode()))
return nil
}
identifyFile(gf(path, "", info.ModTime().Format(time.RFC3339), info.Size()), ctxts, gf)
return nil
}
Expand Down
15 changes: 14 additions & 1 deletion cmd/sf/sf.go
Expand Up @@ -70,8 +70,18 @@ var (

type ModeError os.FileMode

func declarative_lookup(dtyp int, typ string) string {
decl := "file is of type %s; only regular files can be scanned"
switch {
case dtyp == 1:
decl = "file does not have %s; and cannot be scanned"
}
return fmt.Sprintf(decl, typ)
}

func (me ModeError) Error() string {
typ := "unknown"
dtyp := 0
switch {
case os.FileMode(me)&os.ModeDir == os.ModeDir:
typ = "directory"
Expand All @@ -83,8 +93,11 @@ func (me ModeError) Error() string {
typ = "socket"
case os.FileMode(me)&os.ModeDevice == os.ModeDevice:
typ = "device"
case os.FileMode(me)&(256) == 0:
typ = "user read permissions"
dtyp = 1
}
return fmt.Sprintf("file is of type %s; only regular files can be scanned", typ)
return declarative_lookup(dtyp, typ)
}

type WalkError struct {
Expand Down

0 comments on commit ea5300d

Please sign in to comment.