[Ils-source] r1439 - trunk/src/com/resolutions/ils/data

scribe at crosswire.org scribe at crosswire.org
Thu Apr 7 23:11:35 MST 2016


Author: scribe
Date: 2016-04-07 23:11:35 -0700 (Thu, 07 Apr 2016)
New Revision: 1439

Modified:
   trunk/src/com/resolutions/ils/data/CourseAttempt.java
Log:
Fixed mkdirs to assure parents are created when creating the certs folder
added a synchronized block to attempt to deal with a race condition when the same user might possible generate the same course certificate from 2 different sessions


Modified: trunk/src/com/resolutions/ils/data/CourseAttempt.java
===================================================================
--- trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-04-08 05:40:59 UTC (rev 1438)
+++ trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-04-08 06:11:35 UTC (rev 1439)
@@ -793,14 +793,18 @@
 		File sysConfigPath = Utils.getSysConfigFile(null, getCompanyID());
 		File certs = new File(sysConfigPath.getParentFile().getParent(), certsFolder);
 		if (!certs.exists()) {
-			certs.mkdir();
+			certs.mkdirs();
 		}
 		String certName = String.format("%08d_%08d_%08d.pdf", getCourseAttemptUserProfileID(), getCourseAttemptCourseID(), getCourseAttemptID());
 		File cert = new File(certs, certName);
-		if (cert.exists()) {
+		FileOutputStream fos = null;
+		// this synchronized block is mostly worthless as even if users are modifying the same CourseAttempt
+		// record in the database, and thus overwriting the same certificate file, they will still almost
+		// certainly have different CourseAttempt instances, even if they represent the same database row.
+		synchronized (this) {
 			cert.delete();
+			fos = new FileOutputStream(cert);
 		}
-		FileOutputStream fos = new FileOutputStream(cert);
 		fos.write(certData);
 		fos.close();
 	}




More information about the Ils-source mailing list