@@ -116,11 +116,11 @@ public DefaultProjectData(ProjectLocator localStorageLocator, boolean isInWritab
116
116
try {
117
117
init (false , isInWritableProject );
118
118
if (resetOwner ) {
119
- owner = SystemUtilities . getUserName ();
119
+ owner = getUserName ();
120
120
properties .putString (OWNER , owner );
121
121
properties .writeState ();
122
122
}
123
- else if (isInWritableProject && !SystemUtilities . getUserName (). equals (owner )) {
123
+ else if (isInWritableProject && !isOwner (owner )) {
124
124
if (owner == null ) {
125
125
throw new NotOwnerException ("Older projects may only be opened as a View.\n " +
126
126
"You must first create a new project or open an existing current project, \n " +
@@ -185,7 +185,7 @@ public DefaultProjectData(ProjectLocator localStorageLocator, RepositoryAdapter
185
185
DefaultProjectData (LocalFileSystem fileSystem , FileSystem versionedFileSystem )
186
186
throws IOException {
187
187
this .localStorageLocator = new ProjectLocator (null , "Test" );
188
- owner = SystemUtilities . getUserName ();
188
+ owner = getUserName ();
189
189
boolean success = false ;
190
190
try {
191
191
synchronized (fileSystem ) {
@@ -217,6 +217,34 @@ private void initVersionedFSListener() throws IOException {
217
217
}
218
218
}
219
219
220
+ private boolean isOwner (String name ) {
221
+ // Tolerate user name using either the new or old format
222
+ return SystemUtilities .getUserName ().equals (name ) || getUserName ().equals (name );
223
+ }
224
+
225
+ /**
226
+ * Get user name in a format consistent with the older {@link SystemUtilities#getUserName()}
227
+ * implementation. This is done to ensure we can still recognize the OWNER of older
228
+ * projects.
229
+ *
230
+ * @return current user name using legacy formatting.
231
+ */
232
+ private String getUserName () {
233
+ String uname = System .getProperty ("user.name" );
234
+
235
+ // Remove the spaces since some operating systems allow
236
+ // spaces and some do not, Java's File class doesn't
237
+ String userName = uname ;
238
+ if (uname .indexOf (" " ) >= 0 ) {
239
+ userName = "" ;
240
+ StringTokenizer tokens = new StringTokenizer (uname , " " , false );
241
+ while (tokens .hasMoreTokens ()) {
242
+ userName += tokens .nextToken ();
243
+ }
244
+ }
245
+ return userName ;
246
+ }
247
+
220
248
/**
221
249
* Read the contents of the project properties file to include the following values if relavent:
222
250
* {@value #OWNER}, {@value #SERVER_NAME}, {@value #REPOSITORY_NAME}, {@value #PORT_NUMBER}
@@ -276,7 +304,7 @@ private void init(boolean create, boolean isInWritableProject)
276
304
throw new ReadOnlyException (
277
305
"Project " + localStorageLocator .getName () + " is read-only" );
278
306
}
279
- owner = properties .getString (OWNER , SystemUtilities . getUserName ());
307
+ owner = properties .getString (OWNER , getUserName ());
280
308
}
281
309
else {
282
310
owner = "<unknown>" ; // Unknown owner
@@ -298,7 +326,7 @@ private void initLock(boolean creatingProject) throws LockException, IOException
298
326
}
299
327
300
328
if (!properties .exists ()) {
301
- owner = SystemUtilities . getUserName ();
329
+ owner = getUserName ();
302
330
properties .putString (OWNER , owner );
303
331
properties .writeState ();
304
332
}
0 commit comments