diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-03-14 09:17:39 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-03-14 09:17:39 -0700 |
commit | a4a00ea8f15cebf01bc8549aea9058ff48603ab7 (patch) | |
tree | 00df341a3f017863e63790416f7e88ce50c6df94 /org.eclipse.jgit/src/org/eclipse/jgit/util | |
parent | 5f82569cab3386306bca546b87d3919723449c90 (diff) | |
download | jgit-a4a00ea8f15cebf01bc8549aea9058ff48603ab7.tar.gz jgit-a4a00ea8f15cebf01bc8549aea9058ff48603ab7.zip |
FS: Allow userHome to be set and cached
This permits callers to modify the meaning of userHome, which
may be useful if their application allows the user to select
different user settings locations.
Bug: 337101
Change-Id: I076815edeec1c20dea028f7840be3930337dff77
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 51b5a45ac2..a7c0889219 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -99,7 +99,7 @@ public abstract class FS { return new FS_POSIX_Java5(); } - private final File userHome; + private volatile Holder<File> userHome; private volatile Holder<File> gitPrefix; @@ -107,7 +107,7 @@ public abstract class FS { * Constructs a file system abstraction. */ protected FS() { - this.userHome = userHomeImpl(); + // Do nothing by default. } /** @@ -182,7 +182,25 @@ public abstract class FS { * @return the user's home directory; null if the user does not have one. */ 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; } /** |