blob: 4d9afab50dd7496dcfc0a75d8df7b9dc2299384f (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package file
import (
"fmt"
"os"
"strconv"
"strings"
)
type File interface {
String() string
Name() string
}
type FdFile struct {
fd int32
name string
}
func NewFd(fd int32, name string) FdFile {
return FdFile{fd, name}
}
func NewFdWithPid(fd int32, pid uint32) FdFile {
if linkName, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%d", pid, fd)); err == nil {
return FdFile{fd, linkName}
}
return FdFile{fd, "?"}
}
func (f FdFile) Name() string {
return f.name
}
func (f FdFile) String() string {
var sb strings.Builder
if len(f.name) == 0 {
sb.WriteString("?")
} else {
sb.WriteString(f.name)
sb.WriteString(" (")
sb.WriteString(strconv.FormatInt(int64(f.fd), 10))
sb.WriteString(")")
}
return sb.String()
}
type OldnameNewnameFile struct {
Oldname, Newname string
}
func (f OldnameNewnameFile) Name() string {
return f.Newname
}
func (f OldnameNewnameFile) String() string {
var sb strings.Builder
sb.WriteString("old:")
sb.WriteString(f.Oldname)
sb.WriteString(" ->new:")
sb.WriteString(f.Newname)
return sb.String()
}
type PathnameFile struct {
Pathname string
}
func (f PathnameFile) Name() string {
return f.Pathname
}
func (f PathnameFile) String() string {
var sb strings.Builder
sb.WriteString("pathname:")
sb.WriteString(f.Pathname)
return sb.String()
}
|