@@ -12,7 +12,7 @@ const Version = "v0.1.0"
12
12
const Author = "Claudio Ramirez <[email protected] >"
13
13
const Repo = "https://github.com/nxadm/ldifdiff"
14
14
15
- type fn func (string , []string ) (Entries , error )
15
+ type fn func (string , []string ) (entries , error )
16
16
17
17
var skipDnForDelete map [string ]bool
18
18
@@ -83,19 +83,19 @@ func arraysEqual(a, b []string) bool {
83
83
}
84
84
85
85
// Ordering Logic:
86
- // Add : entries from source sorted S -> L. Otherwise is invalid.
86
+ // actionAdd : entries from source sorted S -> L. Otherwise is invalid.
87
87
// Remove: entries from target sorted L -> S. Otherwise is invalid.
88
- // Modify :
88
+ // actionModify :
89
89
// - Keep S -> L ordering
90
90
// - If only 1 instance of attribute with different value on source and target:
91
91
// update. This way we don't break the applicable LDAP schema.
92
- // - extra attribute on source: add
92
+ // - extra attribute on source: actionAdd
93
93
// - extra attribute on target: delete
94
94
95
- func compare (source , target * Entries , dnList * []string ) (string , error ) {
95
+ func compare (source , target * entries , dnList * []string ) (string , error ) {
96
96
var buffer bytes.Buffer
97
97
var err error
98
- queue := make (chan ActionEntry , 10 )
98
+ queue := make (chan actionEntry , 10 )
99
99
var wg sync.WaitGroup
100
100
101
101
// Find the order in which operation must happen
@@ -120,8 +120,8 @@ func compare(source, target *Entries, dnList *[]string) (string, error) {
120
120
close (queue )
121
121
122
122
// Free some memory
123
- * source = Entries {}
124
- * target = Entries {}
123
+ * source = entries {}
124
+ * target = entries {}
125
125
126
126
// Wait for the creation of the LDIF
127
127
wg .Wait ()
@@ -141,17 +141,17 @@ func compare(source, target *Entries, dnList *[]string) (string, error) {
141
141
142
142
func genericDiff (sourceParam , targetParam string , ignoreAttr []string , fn fn , dnList * []string ) (string , error ) {
143
143
// Read the files in memory as a Map with sorted attributes
144
- var source , target Entries
144
+ var source , target entries
145
145
var sourceErr , targetErr error
146
146
var wg sync.WaitGroup
147
147
wg .Add (2 )
148
- go func (entries * Entries , wg * sync.WaitGroup , err * error ) {
148
+ go func (entries * entries , wg * sync.WaitGroup , err * error ) {
149
149
result , e := fn (sourceParam , ignoreAttr )
150
150
* entries = result
151
151
* err = e
152
152
wg .Done ()
153
153
}(& source , & wg , & sourceErr )
154
- go func (entries * Entries , wg * sync.WaitGroup , err * error ) {
154
+ go func (entries * entries , wg * sync.WaitGroup , err * error ) {
155
155
result , e := fn (targetParam , ignoreAttr )
156
156
* entries = result
157
157
* err = e
@@ -172,8 +172,8 @@ func genericDiff(sourceParam, targetParam string, ignoreAttr []string, fn fn, dn
172
172
173
173
func sendForAddition (
174
174
orderedSourceShortToLong * []string ,
175
- source , target * Entries ,
176
- queue chan <- ActionEntry ,
175
+ source , target * entries ,
176
+ queue chan <- actionEntry ,
177
177
dnList * []string ) {
178
178
for _ , dn := range * orderedSourceShortToLong {
179
179
// Ignore equal entries
@@ -185,17 +185,17 @@ func sendForAddition(
185
185
// Mark entries for addition if only on source
186
186
if _ , ok := (* target )[dn ]; ! ok {
187
187
if dnList == nil {
188
- subActionAttr := make (map [SubAction ][]string )
189
- subActionAttr [None ] = (* source )[dn ]
188
+ subActionAttr := make (map [subAction ][]string )
189
+ subActionAttr [subActionNone ] = (* source )[dn ]
190
190
actionEntry :=
191
- ActionEntry {
191
+ actionEntry {
192
192
Dn : dn ,
193
- Action : Add ,
194
- SubActionAttrs : []SubActionAttr {subActionAttr },
193
+ Action : actionAdd ,
194
+ SubActionAttrs : []subActionAttrs {subActionAttr },
195
195
}
196
196
queue <- actionEntry
197
197
} else {
198
- // Always add (attributes not relevant)
198
+ // Always actionAdd (attributes not relevant)
199
199
* dnList = append (* dnList , dn )
200
200
}
201
201
delete (* source , dn )
@@ -208,8 +208,8 @@ func sendForAddition(
208
208
209
209
func sendForDeletion (
210
210
orderedTargetLongToShort * []string ,
211
- source , target * Entries ,
212
- queue chan <- ActionEntry ,
211
+ source , target * entries ,
212
+ queue chan <- actionEntry ,
213
213
dnList * []string ) {
214
214
for _ , dn := range * orderedTargetLongToShort {
215
215
if skipDnForDelete [dn ] { // We know it's not a delete operation
@@ -218,13 +218,13 @@ func sendForDeletion(
218
218
if _ , ok := (* target )[dn ]; ok { // It has not been deleted above
219
219
if _ , ok := (* source )[dn ]; ! ok { // does not exists on source
220
220
if dnList == nil {
221
- subActionAttr := make (map [SubAction ][]string )
222
- subActionAttr [None ] = nil
221
+ subActionAttr := make (map [subAction ][]string )
222
+ subActionAttr [subActionNone ] = nil
223
223
actionEntry :=
224
- ActionEntry {
224
+ actionEntry {
225
225
Dn : dn ,
226
- Action : Delete ,
227
- SubActionAttrs : []SubActionAttr {subActionAttr },
226
+ Action : actionDelete ,
227
+ SubActionAttrs : []subActionAttrs {subActionAttr },
228
228
}
229
229
queue <- actionEntry
230
230
} else {
@@ -244,8 +244,8 @@ func sendForDeletion(
244
244
245
245
func sendForModification (
246
246
orderedSourceShortToLong * []string , source ,
247
- target * Entries ,
248
- queue chan <- ActionEntry ,
247
+ target * entries ,
248
+ queue chan <- actionEntry ,
249
249
dnList * []string ) {
250
250
for _ , dn := range * orderedSourceShortToLong {
251
251
// DN is present on source and target:
@@ -275,9 +275,9 @@ func sendForModification(
275
275
if _ , ok := targetAttr [attr ]; ! ok {
276
276
// Is the attribute name (not value) unique?
277
277
switch uniqueAttrName (attr , sourceAttr , targetAttr ) {
278
- case true : // This is a Modify -Replace operation
278
+ case true : // This is a actionModify -Replace operation
279
279
attrToModifyReplace = append (attrToModifyReplace , attr )
280
- case false : // This is just a Modify Add (only on source).
280
+ case false : // This is just a actionModify actionAdd (only on source).
281
281
attrToModifyAdd = append (attrToModifyAdd , attr )
282
282
}
283
283
}
@@ -294,17 +294,17 @@ func sendForModification(
294
294
}
295
295
296
296
// Send it
297
- actionEntry := ActionEntry {Dn : dn , Action : Modify }
298
- subActionAttrArray := []SubActionAttr {}
297
+ actionEntry := actionEntry {Dn : dn , Action : actionModify }
298
+ subActionAttrArray := []subActionAttrs {}
299
299
switch {
300
300
case len (attrToModifyAdd ) > 0 :
301
- subActionAttrArray = append (subActionAttrArray , SubActionAttr { ModifyAdd : attrToModifyAdd })
301
+ subActionAttrArray = append (subActionAttrArray , subActionAttrs { subActionModifyAdd : attrToModifyAdd })
302
302
fallthrough
303
303
case len (attrToModifyDelete ) > 0 :
304
- subActionAttrArray = append (subActionAttrArray , SubActionAttr { ModifyDelete : attrToModifyDelete })
304
+ subActionAttrArray = append (subActionAttrArray , subActionAttrs { subActionModifyDelete : attrToModifyDelete })
305
305
fallthrough
306
306
case len (attrToModifyReplace ) > 0 :
307
- subActionAttrArray = append (subActionAttrArray , SubActionAttr { ModifyReplace : attrToModifyReplace })
307
+ subActionAttrArray = append (subActionAttrArray , subActionAttrs { subActionModifyReplace : attrToModifyReplace })
308
308
}
309
309
310
310
actionEntry .SubActionAttrs = subActionAttrArray
@@ -322,7 +322,7 @@ func sendForModification(
322
322
}
323
323
}
324
324
325
- func sortDnByDepth (entries * Entries , longToShort bool ) []string {
325
+ func sortDnByDepth (entries * entries , longToShort bool ) []string {
326
326
var sorted []string
327
327
328
328
dns := []string {}
0 commit comments