File: modeType.go

package info (click to toggle)
golang-github-karrick-godirwalk 1.15.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 248 kB
  • sloc: makefile: 3
file content (22 lines) | stat: -rw-r--r-- 693 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package godirwalk

import (
	"os"
)

// modeType returns the mode type of the file system entry identified by
// osPathname by calling os.LStat function, to intentionally not follow symbolic
// links.
//
// Even though os.LStat provides all file mode bits, we want to ensure same
// values returned to caller regardless of whether we obtained file mode bits
// from syscall or stat call.  Therefore mask out the additional file mode bits
// that are provided by stat but not by the syscall, so users can rely on their
// values.
func modeType(osPathname string) (os.FileMode, error) {
	fi, err := os.Lstat(osPathname)
	if err == nil {
		return fi.Mode() & os.ModeType, nil
	}
	return 0, err
}