1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package main
import (
"os"
"path"
)
func CheckDirent(fname string) {
defer tracecall("CheckDirent", fname)()
st, err := os.Lstat(fname)
if err != nil || !st.Mode().IsDir() && !st.Mode().IsRegular() {
errorf(fname, noLines, "No such file or directory.")
return
}
isDir := st.Mode().IsDir()
isReg := st.Mode().IsRegular()
G.currentDir = ifelseStr(isReg, path.Dir(fname), fname)
absCurrentDir := abspath(G.currentDir)
G.isWip = !G.opts.Import && matches(absCurrentDir, `/wip/|/wip$`)
G.isInfrastructure = matches(absCurrentDir, `/mk/|/mk$`)
G.curPkgsrcdir = findPkgsrcTopdir(G.currentDir)
if G.curPkgsrcdir == "" {
errorf(fname, noLines, "Cannot determine the pkgsrc root directory for %q.", G.currentDir)
return
}
switch {
case isDir && isEmptyDir(fname):
return
case isReg:
checkfile(fname)
return
}
switch G.curPkgsrcdir {
case "../..":
checkdirPackage(relpath(G.globalData.pkgsrcdir, G.currentDir))
case "..":
checkdirCategory()
case ".":
checkdirToplevel()
default:
errorf(fname, noLines, "Cannot check directories outside a pkgsrc tree.")
}
}
|