Skip to content

Commit 5de4645

Browse files
committed
wip
1 parent 93d304e commit 5de4645

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

input.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ func importLdifFile(file string, ignoreAttr []string) (entries, error) {
2828
func addLineToRecord(line *string, record *[]string, ignoreAttr []string, prevAttrSkipped *bool) error {
2929
var err error
3030

31-
// Skip comments
32-
if strings.HasPrefix(*line, "#") {
33-
return nil
34-
}
35-
3631
// Append continuation lines to previous line
3732
if strings.HasPrefix(*line, " ") {
3833
if *prevAttrSkipped { // but not lines from a skipped attribute
@@ -107,8 +102,26 @@ func readFile(file string, ignoreAttr []string, queue chan<- []string, wg *sync.
107102
record := []string{}
108103
scanner := bufio.NewScanner(fh)
109104
var prevAttrSkipped bool // use to skip continuation lines of skipped attr
105+
firstLine := true
110106
for scanner.Scan() {
107+
111108
line := scanner.Text()
109+
110+
// Skip comments
111+
if strings.HasPrefix(line, "#") {
112+
continue
113+
}
114+
115+
// Check if first line is a "version: *" line and skip it
116+
if firstLine {
117+
if strings.HasPrefix(line, "version: ") {
118+
firstLine = false
119+
continue
120+
}
121+
firstLine = false
122+
}
123+
124+
// Import lines as records
112125
*err = addLineToRecord(&line, &record, ignoreAttr, &prevAttrSkipped)
113126
if *err != nil {
114127
return
@@ -134,10 +147,25 @@ func readFile(file string, ignoreAttr []string, queue chan<- []string, wg *sync.
134147
func readStr(ldifStr string, ignoreAttr []string, queue chan<- []string, wg *sync.WaitGroup, err *error) {
135148
defer wg.Done()
136149
defer close(queue)
137-
for _, recordStr := range strings.Split(ldifStr, "\n\n") {
150+
151+
for idx, recordStr := range strings.Split(ldifStr, "\n\n") {
138152
var prevAttrSkipped bool
139153
record := []string{}
140154
for _, line := range strings.Split(recordStr, "\n") {
155+
156+
// Skip comments
157+
if strings.HasPrefix(line, "#") {
158+
continue
159+
}
160+
161+
// Check if first "record" is a "version: *" line and skip it
162+
// TODO: version and dn on some record
163+
if idx == 0 {
164+
if strings.HasPrefix(line, "version: ") {
165+
continue
166+
}
167+
}
168+
141169
*err = addLineToRecord(&line, &record, ignoreAttr, &prevAttrSkipped)
142170
if *err != nil {
143171
return

0 commit comments

Comments
 (0)