From cf75e8eef6b91f238b34e81303dc7f60ae230def Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Fri, 25 Jul 2008 16:58:45 +0000
Subject: [PATCH] fix for having a regular user association and then one
 associated with a partition

---
 .../mysql/accounting_storage_mysql.c          | 20 +++++++-------
 src/sacctmgr/association_functions.c          |  2 +-
 src/sacctmgr/common.c                         | 27 +++++++++++++------
 src/sacctmgr/user_functions.c                 |  7 ++---
 4 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
index 0e06f7ce471..a6ae87ddb66 100644
--- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
+++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
@@ -2377,20 +2377,22 @@ extern int acct_storage_p_add_associations(mysql_conn_t *mysql_conn,
 		}
 		
 		if(object->user) {
+			char *part = object->partition;
 			xstrcat(cols, ", user");
 			xstrfmtcat(vals, ", '%s'", object->user); 		
 			xstrfmtcat(extra, ", user='%s'", object->user);
 			xstrfmtcat(update, " && user='%s'",
 				   object->user); 
-			
-			if(object->partition) {
-				xstrcat(cols, ", partition");
-				xstrfmtcat(vals, ", '%s'", object->partition);
-				xstrfmtcat(extra, ", partition='%s'",
-					   object->partition);
-				xstrfmtcat(update, " && partition='%s'",
-					   object->partition);
-			}
+
+			/* We need to give a partition wiether it be
+			 * '' or the actual partition name given
+			 */
+			if(!part)
+				part = "";
+			xstrcat(cols, ", partition");
+			xstrfmtcat(vals, ", '%s'", part);
+			xstrfmtcat(extra, ", partition='%s'", part);
+			xstrfmtcat(update, " && partition='%s'", part);
 		}
 
 		if((int)object->fairshare >= 0) {
diff --git a/src/sacctmgr/association_functions.c b/src/sacctmgr/association_functions.c
index 461a19fdb31..3eb5a88793c 100644
--- a/src/sacctmgr/association_functions.c
+++ b/src/sacctmgr/association_functions.c
@@ -370,7 +370,7 @@ extern int sacctmgr_list_association(int argc, char *argv[])
 		return SLURM_ERROR;
 	} else if(!list_count(format_list)) 
 		slurm_addto_char_list(format_list,
-				      "C,A,U,F,MaxC,MaxJ,MaxN,MaxW");
+				      "C,A,U,Part,F,MaxC,MaxJ,MaxN,MaxW");
 
 	print_fields_list = list_create(destroy_print_field);
 
diff --git a/src/sacctmgr/common.c b/src/sacctmgr/common.c
index d043fcdf95a..23320d49515 100644
--- a/src/sacctmgr/common.c
+++ b/src/sacctmgr/common.c
@@ -132,6 +132,12 @@ extern char *strip_quotes(char *option, int *increased)
 			break;
 		} else if(option[i] == '\"' || option[i] == '\'')
 			option[i] = '`';
+		else {
+			char lower = tolower(option[i]);
+			if(lower != option[i])
+				option[i] = lower;
+		}
+		
 		i++;
 	}
 	end += i;
@@ -393,14 +399,19 @@ extern acct_association_rec_t *sacctmgr_find_association_from_list(
 	
 	itr = list_iterator_create(assoc_list);
 	while((assoc = list_next(itr))) {
-		if((user && (!assoc->user || strcasecmp(user, assoc->user)))
-		   || (account && (!assoc->acct 
-				   || strcasecmp(account, assoc->acct)))
-		   || (cluster && (!assoc->cluster 
-				   || strcasecmp(cluster, assoc->cluster)))
-		   || (partition && (!assoc->partition 
-				     || strcasecmp(partition, 
-						   assoc->partition))))
+		if(((!user && assoc->user)
+		    || (user && (!assoc->user
+				 || strcasecmp(user, assoc->user))))
+		   || ((!account && assoc->acct)
+		       || (account && (!assoc->acct 
+				       || strcasecmp(account, assoc->acct))))
+		   || ((!cluster && assoc->cluster)
+		       || (cluster && (!assoc->cluster 
+				       || strcasecmp(cluster, assoc->cluster))))
+		   || ((!partition && assoc->partition)
+		       || (partition && (!assoc->partition 
+					 || strcasecmp(partition, 
+						       assoc->partition)))))
 			continue;
 		break;
 	}
diff --git a/src/sacctmgr/user_functions.c b/src/sacctmgr/user_functions.c
index acaf69df75e..6d42d0249fa 100644
--- a/src/sacctmgr/user_functions.c
+++ b/src/sacctmgr/user_functions.c
@@ -619,9 +619,10 @@ extern int sacctmgr_add_user(int argc, char *argv[])
 
 				if(sacctmgr_find_association_from_list(
 					   local_assoc_list,
-					   name, account, cluster, NULL))
-						continue;
-					
+					   name, account, cluster, NULL)) {
+					continue;
+				}		
+			
 				assoc = xmalloc(sizeof(acct_association_rec_t));
 				assoc->user = xstrdup(name);
 				assoc->acct = xstrdup(account);
-- 
GitLab