File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 5151import org .apache .hadoop .fs .permission .FsPermission ;
5252import org .apache .hadoop .security .AccessControlException ;
5353import org .apache .hadoop .security .SecurityUtil ;
54+ import org .apache .hadoop .security .UserGroupInformation ;
5455import org .apache .hadoop .security .token .Token ;
5556import org .apache .hadoop .util .LambdaUtils ;
5657import org .apache .hadoop .util .Progressable ;
@@ -456,8 +457,16 @@ public Path getInitialWorkingDirectory() {
456457 * @return current user's home directory.
457458 */
458459 public Path getHomeDirectory () {
459- return new Path ("/user/" +System .getProperty ("user.name" )).makeQualified (
460- getUri (), null );
460+ String username ;
461+ try {
462+ username = UserGroupInformation .getCurrentUser ().getShortUserName ();
463+ } catch (IOException ex ) {
464+ LOG .warn ("Unable to get user name. Fall back to system property " +
465+ "user.name" , ex );
466+ username = System .getProperty ("user.name" );
467+ }
468+ return new Path ("/user/" + username )
469+ .makeQualified (getUri (), null );
461470 }
462471
463472 /**
Original file line number Diff line number Diff line change @@ -2270,8 +2270,16 @@ public LocatedFileStatus next() throws IOException {
22702270 * The default implementation returns {@code "/user/$USER/"}.
22712271 */
22722272 public Path getHomeDirectory () {
2273+ String username ;
2274+ try {
2275+ username = UserGroupInformation .getCurrentUser ().getShortUserName ();
2276+ } catch (IOException ex ) {
2277+ LOGGER .warn ("Unable to get user name. Fall back to system property " +
2278+ "user.name" , ex );
2279+ username = System .getProperty ("user.name" );
2280+ }
22732281 return this .makeQualified (
2274- new Path (USER_HOME_PREFIX + "/" + System . getProperty ( "user.name" ) ));
2282+ new Path (USER_HOME_PREFIX + "/" + username ));
22752283 }
22762284
22772285
You can’t perform that action at this time.
0 commit comments