瀏覽代碼

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>
tags/v0.12.1
Shawn O. Pearce 13 年之前
父節點
當前提交
a4a00ea8f1
共有 1 個檔案被更改,包括 21 行新增3 行删除
  1. 21
    3
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

+ 21
- 3
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;
}

/**

Loading…
取消
儲存