@@ -28,11 +28,6 @@ func importLdifFile(file string, ignoreAttr []string) (entries, error) {
28
28
func addLineToRecord (line * string , record * []string , ignoreAttr []string , prevAttrSkipped * bool ) error {
29
29
var err error
30
30
31
- // Skip comments
32
- if strings .HasPrefix (* line , "#" ) {
33
- return nil
34
- }
35
-
36
31
// Append continuation lines to previous line
37
32
if strings .HasPrefix (* line , " " ) {
38
33
if * prevAttrSkipped { // but not lines from a skipped attribute
@@ -107,8 +102,28 @@ func readFile(file string, ignoreAttr []string, queue chan<- []string, wg *sync.
107
102
record := []string {}
108
103
scanner := bufio .NewScanner (fh )
109
104
var prevAttrSkipped bool // use to skip continuation lines of skipped attr
105
+ firstLine := true
110
106
for scanner .Scan () {
107
+
111
108
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
+ } else if line == "" {
121
+ continue
122
+ }
123
+ firstLine = false
124
+ }
125
+
126
+ // Import lines as records
112
127
* err = addLineToRecord (& line , & record , ignoreAttr , & prevAttrSkipped )
113
128
if * err != nil {
114
129
return
@@ -134,10 +149,23 @@ func readFile(file string, ignoreAttr []string, queue chan<- []string, wg *sync.
134
149
func readStr (ldifStr string , ignoreAttr []string , queue chan <- []string , wg * sync.WaitGroup , err * error ) {
135
150
defer wg .Done ()
136
151
defer close (queue )
137
- for _ , recordStr := range strings .Split (ldifStr , "\n \n " ) {
152
+
153
+ for idx , recordStr := range strings .Split (ldifStr , "\n \n " ) {
138
154
var prevAttrSkipped bool
139
155
record := []string {}
140
156
for _ , line := range strings .Split (recordStr , "\n " ) {
157
+
158
+ // Skip comments
159
+ if strings .HasPrefix (line , "#" ) {
160
+ continue
161
+ }
162
+
163
+ if idx == 0 { // First record only
164
+ if strings .HasPrefix (line , "version: " ) {
165
+ continue
166
+ }
167
+ }
168
+
141
169
* err = addLineToRecord (& line , & record , ignoreAttr , & prevAttrSkipped )
142
170
if * err != nil {
143
171
return
0 commit comments