Merge "FS: Allow userHome to be set and cached"

This commit is contained in:
Chris Aniszczyk 2011-03-15 11:05:37 -04:00 committed by Code Review
commit 786707fdfe
1 changed files with 21 additions and 3 deletions

View File

@ -99,7 +99,7 @@ public static FS detect(Boolean cygwinUsed) {
return new FS_POSIX_Java5(); return new FS_POSIX_Java5();
} }
private final File userHome; private volatile Holder<File> userHome;
private volatile Holder<File> gitPrefix; private volatile Holder<File> gitPrefix;
@ -107,7 +107,7 @@ public static FS detect(Boolean cygwinUsed) {
* Constructs a file system abstraction. * Constructs a file system abstraction.
*/ */
protected FS() { protected FS() {
this.userHome = userHomeImpl(); // Do nothing by default.
} }
/** /**
@ -182,7 +182,25 @@ public File resolve(final File dir, final String name) {
* @return the user's home directory; null if the user does not have one. * @return the user's home directory; null if the user does not have one.
*/ */
public File userHome() { public File userHome() {
return userHome; Holder<File> p = userHome;
if (p == null) {
p = new Holder<File>(userHomeImpl());
userHome = p;
}
return p.value;
}
/**
* Set the user's home directory location.
*
* @param path
* the location of the user's preferences; null if there is no
* home directory for the current user.
* @return {@code this}.
*/
public FS setUserHome(File path) {
userHome = new Holder<File>(path);
return this;
} }
/** /**