@@ -21,7 +21,7 @@ import (
21
21
// io.Reader `r` is to the file stream for the file payload. While this
22
22
// function takes an io.Reader, the caller needs to reset it to the beginning
23
23
// for each new KeywordFunc
24
- type KeywordFunc func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error )
24
+ type KeywordFunc func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error )
25
25
26
26
var (
27
27
// KeywordFuncs is the map of all keywords (and the functions to produce them)
67
67
}
68
68
)
69
69
var (
70
- modeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
70
+ modeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
71
71
permissions := info .Mode ().Perm ()
72
72
if os .ModeSetuid & info .Mode () > 0 {
73
73
permissions |= (1 << 11 )
@@ -78,93 +78,93 @@ var (
78
78
if os .ModeSticky & info .Mode () > 0 {
79
79
permissions |= (1 << 9 )
80
80
}
81
- return KeyVal (fmt .Sprintf ("mode=%#o" , permissions )), nil
81
+ return [] KeyVal { KeyVal (fmt .Sprintf ("mode=%#o" , permissions ))} , nil
82
82
}
83
- sizeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
83
+ sizeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
84
84
if sys , ok := info .Sys ().(* tar.Header ); ok {
85
85
if sys .Typeflag == tar .TypeSymlink {
86
- return KeyVal (fmt .Sprintf ("size=%d" , len (sys .Linkname ))), nil
86
+ return [] KeyVal { KeyVal (fmt .Sprintf ("size=%d" , len (sys .Linkname )))} , nil
87
87
}
88
88
}
89
- return KeyVal (fmt .Sprintf ("size=%d" , info .Size ())), nil
89
+ return [] KeyVal { KeyVal (fmt .Sprintf ("size=%d" , info .Size ()))} , nil
90
90
}
91
- cksumKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
91
+ cksumKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
92
92
if ! info .Mode ().IsRegular () {
93
- return emptyKV , nil
93
+ return nil , nil
94
94
}
95
95
sum , _ , err := cksum (r )
96
96
if err != nil {
97
- return emptyKV , err
97
+ return nil , err
98
98
}
99
- return KeyVal (fmt .Sprintf ("cksum=%d" , sum )), nil
99
+ return [] KeyVal { KeyVal (fmt .Sprintf ("cksum=%d" , sum ))} , nil
100
100
}
101
101
hasherKeywordFunc = func (name string , newHash func () hash.Hash ) KeywordFunc {
102
- return func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
102
+ return func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
103
103
if ! info .Mode ().IsRegular () {
104
- return emptyKV , nil
104
+ return nil , nil
105
105
}
106
106
h := newHash ()
107
107
if _ , err := io .Copy (h , r ); err != nil {
108
- return emptyKV , err
108
+ return nil , err
109
109
}
110
- return KeyVal (fmt .Sprintf ("%s=%x" , KeywordSynonym (name ), h .Sum (nil ))), nil
110
+ return [] KeyVal { KeyVal (fmt .Sprintf ("%s=%x" , KeywordSynonym (name ), h .Sum (nil )))} , nil
111
111
}
112
112
}
113
- tartimeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
114
- return KeyVal (fmt .Sprintf ("tar_time=%d.%9.9d" , info .ModTime ().Unix (), 0 )), nil
113
+ tartimeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
114
+ return [] KeyVal { KeyVal (fmt .Sprintf ("tar_time=%d.%9.9d" , info .ModTime ().Unix (), 0 ))} , nil
115
115
}
116
- timeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
116
+ timeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
117
117
tSec := info .ModTime ().Unix ()
118
118
tNano := info .ModTime ().Nanosecond ()
119
- return KeyVal (fmt .Sprintf ("time=%d.%9.9d" , tSec , tNano )), nil
119
+ return [] KeyVal { KeyVal (fmt .Sprintf ("time=%d.%9.9d" , tSec , tNano ))} , nil
120
120
}
121
- linkKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
121
+ linkKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
122
122
if sys , ok := info .Sys ().(* tar.Header ); ok {
123
123
if sys .Linkname != "" {
124
124
linkname , err := govis .Vis (sys .Linkname , DefaultVisFlags )
125
125
if err != nil {
126
- return emptyKV , err
126
+ return nil , nil
127
127
}
128
- return KeyVal (fmt .Sprintf ("link=%s" , linkname )), nil
128
+ return [] KeyVal { KeyVal (fmt .Sprintf ("link=%s" , linkname ))} , nil
129
129
}
130
- return emptyKV , nil
130
+ return nil , nil
131
131
}
132
132
133
133
if info .Mode ()& os .ModeSymlink != 0 {
134
134
str , err := os .Readlink (path )
135
135
if err != nil {
136
- return emptyKV , err
136
+ return nil , nil
137
137
}
138
138
linkname , err := govis .Vis (str , DefaultVisFlags )
139
139
if err != nil {
140
- return emptyKV , err
140
+ return nil , nil
141
141
}
142
- return KeyVal (fmt .Sprintf ("link=%s" , linkname )), nil
142
+ return [] KeyVal { KeyVal (fmt .Sprintf ("link=%s" , linkname ))} , nil
143
143
}
144
- return emptyKV , nil
144
+ return nil , nil
145
145
}
146
- typeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) (KeyVal , error ) {
146
+ typeKeywordFunc = func (path string , info os.FileInfo , r io.Reader ) ([] KeyVal , error ) {
147
147
if info .Mode ().IsDir () {
148
- return "type=dir" , nil
148
+ return [] KeyVal { "type=dir" } , nil
149
149
}
150
150
if info .Mode ().IsRegular () {
151
- return "type=file" , nil
151
+ return [] KeyVal { "type=file" } , nil
152
152
}
153
153
if info .Mode ()& os .ModeSocket != 0 {
154
- return "type=socket" , nil
154
+ return [] KeyVal { "type=socket" } , nil
155
155
}
156
156
if info .Mode ()& os .ModeSymlink != 0 {
157
- return "type=link" , nil
157
+ return [] KeyVal { "type=link" } , nil
158
158
}
159
159
if info .Mode ()& os .ModeNamedPipe != 0 {
160
- return "type=fifo" , nil
160
+ return [] KeyVal { "type=fifo" } , nil
161
161
}
162
162
if info .Mode ()& os .ModeDevice != 0 {
163
163
if info .Mode ()& os .ModeCharDevice != 0 {
164
- return "type=char" , nil
164
+ return [] KeyVal { "type=char" } , nil
165
165
}
166
- return "type=block" , nil
166
+ return [] KeyVal { "type=block" } , nil
167
167
}
168
- return emptyKV , nil
168
+ return nil , nil
169
169
}
170
170
)
0 commit comments