@@ -34,23 +34,17 @@ func localDirs(gitHome string) ([]string, error) {
3434 return ret , nil
3535}
3636
37- // getDisjunction gets the items that are in namespaceList and not in dirs or vice versa
38- func getDisjunction (namespaceList []api.Namespace , dirs []string ) []string {
37+ // getDiff gets the directories that are not in namespaceList
38+ func getDiff (namespaceList []api.Namespace , dirs []string ) []string {
3939 var ret []string
40- namespacesSet := make (map [string ]struct {})
41- dirsSet := make (map [string ]struct {})
4240
43- // create sets of the namespaces and dirs
41+ // create a set of lowercase namespace names
42+ namespacesSet := make (map [string ]struct {})
4443 for _ , ns := range namespaceList {
4544 lowerName := strings .ToLower (ns .Name )
4645 namespacesSet [lowerName ] = struct {}{}
4746 }
4847
49- for _ , dir := range dirs {
50- lowerName := strings .ToLower (dir )
51- dirsSet [lowerName ] = struct {}{}
52- }
53-
5448 // get dirs not in the namespaces set
5549 for _ , dir := range dirs {
5650 lowerName := strings .ToLower (dir )
@@ -59,14 +53,6 @@ func getDisjunction(namespaceList []api.Namespace, dirs []string) []string {
5953 }
6054 }
6155
62- // get namespaces not in the dirs set
63- for _ , ns := range namespaceList {
64- lowerName := strings .ToLower (ns .Name )
65- if _ , ok := dirsSet [lowerName ]; ! ok {
66- ret = append (ret , lowerName )
67- }
68- }
69-
7056 return ret
7157}
7258
@@ -84,17 +70,17 @@ func Run(gitHome string, nsLister k8s.NamespaceLister, repoLock sshd.RepositoryL
8470 log .Debug ("Cleaner error listing local git directories (%s)" , err )
8571 }
8672
87- disjunctions := getDisjunction (nsList .Items , gitDirs )
88- for _ , disj := range disjunctions {
89- if err := repoLock .Lock (disj , time .Duration (0 )); err != nil {
90- log .Debug ("Cleaner error locking repository %s for deletion (%s)" , disj , err )
73+ dirsToDelete := getDiff (nsList .Items , gitDirs )
74+ for _ , dirToDelete := range dirsToDelete {
75+ if err := repoLock .Lock (dirToDelete , time .Duration (0 )); err != nil {
76+ log .Debug ("Cleaner error locking repository %s for deletion (%s)" , dirToDelete , err )
9177 continue
9278 }
93- if err := os .RemoveAll (disj ); err != nil {
94- log .Debug ("Cleaner error removing deleted app %s (%s)" , disj , err )
79+ if err := os .RemoveAll (dirToDelete ); err != nil {
80+ log .Debug ("Cleaner error removing deleted app %s (%s)" , dirToDelete , err )
9581 }
96- if err := repoLock .Unlock (disj , time .Duration (0 )); err != nil {
97- log .Debug ("Cleaner error unlocking repository %s for deletion (%s)" , disj , err )
82+ if err := repoLock .Unlock (dirToDelete , time .Duration (0 )); err != nil {
83+ log .Debug ("Cleaner error unlocking repository %s for deletion (%s)" , dirToDelete , err )
9884 continue
9985 }
10086 }
0 commit comments