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
Original file line number Original file line Diff line number Diff line change
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())) printFile(ctxts, gf(path, "", info.ModTime().Format(time.RFC3339), info.Size()), ModeError(info.Mode()))
return nil 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) identifyFile(gf(path, "", info.ModTime().Format(time.RFC3339), info.Size()), ctxts, gf)
return nil return nil
} }
Expand Down
15 changes: 14 additions & 1 deletion cmd/sf/sf.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ var (


type ModeError os.FileMode 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 { func (me ModeError) Error() string {
typ := "unknown" typ := "unknown"
dtyp := 0
switch { switch {
case os.FileMode(me)&os.ModeDir == os.ModeDir: case os.FileMode(me)&os.ModeDir == os.ModeDir:
typ = "directory" typ = "directory"
Expand All @@ -83,8 +93,11 @@ func (me ModeError) Error() string {
typ = "socket" typ = "socket"
case os.FileMode(me)&os.ModeDevice == os.ModeDevice: case os.FileMode(me)&os.ModeDevice == os.ModeDevice:
typ = "device" 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 { type WalkError struct {
Expand Down

0 comments on commit ea5300d

Please sign in to comment.