@@ -28,11 +28,6 @@ func importLdifFile(file string, ignoreAttr []string) (entries, error) {
2828func 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,28 @@ 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+ } else if line == "" {
121+ continue
122+ }
123+ firstLine = false
124+ }
125+
126+ // Import lines as records
112127 * err = addLineToRecord (& line , & record , ignoreAttr , & prevAttrSkipped )
113128 if * err != nil {
114129 return
@@ -134,10 +149,23 @@ func readFile(file string, ignoreAttr []string, queue chan<- []string, wg *sync.
134149func readStr (ldifStr string , ignoreAttr []string , queue chan <- []string , wg * sync.WaitGroup , err * error ) {
135150 defer wg .Done ()
136151 defer close (queue )
137- for _ , recordStr := range strings .Split (ldifStr , "\n \n " ) {
152+
153+ for idx , recordStr := range strings .Split (ldifStr , "\n \n " ) {
138154 var prevAttrSkipped bool
139155 record := []string {}
140156 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+
141169 * err = addLineToRecord (& line , & record , ignoreAttr , & prevAttrSkipped )
142170 if * err != nil {
143171 return
0 commit comments