@@ -160,13 +160,6 @@ func contains(slice []string, value string) bool {
160
160
return false
161
161
}
162
162
163
- func remove (slice []int , index int ) []int {
164
- if index < 0 || index >= len (slice ) {
165
- return slice // Return the original slice if the index is out of bounds
166
- }
167
- return append (slice [:index ], slice [index + 1 :]... )
168
- }
169
-
170
163
func findDuplicateNodes (aclNodes []aclNode ) [3 ]map [string ][]string {
171
164
du := make (map [string ][]string )
172
165
dg := make (map [string ][]string )
@@ -226,7 +219,7 @@ func queryDuplicateNodes(hc *dgraphapi.HTTPClient) ([3]map[string][]string, erro
226
219
return findDuplicateNodes (result .Data .Nodes ), nil
227
220
}
228
221
229
- func printDuplicates (hc * dgraphapi.HTTPClient , entityType string , ns uint64 , nodesmap map [string ][]string ,
222
+ func printAndDeleteDuplicates (hc * dgraphapi.HTTPClient , entityType string , ns uint64 , nodesmap map [string ][]string ,
230
223
dupDelete bool ) error {
231
224
if len (nodesmap ) == 0 {
232
225
return nil
@@ -502,7 +495,8 @@ func init() {
502
495
flag .String (namespace , "" , "Namespace to check for duplicate nodes" )
503
496
flag .String (dgUser , "groot" , "Username of the namespace's user" )
504
497
flag .String (password , "password" , "Password of the namespace's user" )
505
- flag .String (aclSecretKeyFilePath , "" , "path of file that stores secret key or private key, which is used to sign the ACL JWT" )
498
+ flag .String (aclSecretKeyFilePath , "" , "path of file that stores secret key or private key," +
499
+ " which is used to sign the ACL JWT" )
506
500
flag .String (jwtAlg , "HS256" , "JWT signing algorithm" )
507
501
flag .String (deleteDup , "false" , "set this flag to true to delete duplicates nodes" )
508
502
}
@@ -551,21 +545,29 @@ func checkUpgrade() error {
551
545
return errors .Wrapf (err , "while getting access jwt token for namespace %v" , ns )
552
546
}
553
547
} else {
554
- hc .LoginIntoNamespace (cmdInput .dgUser , cmdInput .password , ns )
548
+ if err := hc .LoginIntoNamespace (cmdInput .dgUser , cmdInput .password , ns ); err != nil {
549
+ return errors .Wrapf (err , "while logging into namespace %v" , ns )
550
+ }
555
551
}
556
552
557
553
duplicates , err := queryDuplicateNodes (hc )
558
554
if err != nil {
559
555
return err
560
556
}
561
- printDuplicates (hc , "user" , ns , duplicates [0 ], cmdInput .dupDelete )
557
+ if err := printAndDeleteDuplicates (hc , "user" , ns , duplicates [0 ], cmdInput .dupDelete ); err != nil {
558
+ return err
559
+ }
562
560
// example output:
563
561
// Found duplicate users in namespace: #0
564
562
// dgraph.xid user1 , Uids: [0x4 0x3]
565
- printDuplicates (hc , "group" , ns , duplicates [1 ], cmdInput .dupDelete )
563
+ if err := printAndDeleteDuplicates (hc , "group" , ns , duplicates [1 ], cmdInput .dupDelete ); err != nil {
564
+ return err
565
+ }
566
566
// Found duplicate groups in namespace: #1
567
567
// dgraph.xid group1 , Uids: [0x2714 0x2711]
568
- printDuplicates (hc , "groups and user" , ns , duplicates [2 ], cmdInput .dupDelete )
568
+ if err := printAndDeleteDuplicates (hc , "groups and user" , ns , duplicates [2 ], cmdInput .dupDelete ); err != nil {
569
+ return err
570
+ }
569
571
// Found duplicate groups and users in namespace: #0
570
572
// dgraph.xid userGroup1 , Uids: [0x7532 0x7531]
571
573
}
0 commit comments