Skip to content

Commit b189df0

Browse files
committed
Fixed: #65 implemented DUB_HOME
1 parent 3d67979 commit b189df0

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

source/redub/api.d

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,38 @@ bool isIncremental(Inference incremental, ProjectNode tree)
835835
string getDubWorkspacePath()
836836
{
837837
import std.process;
838+
import std.path :isAbsolute;
838839
import redub.parsers.environment;
839840
import redub.misc.path;
840841

841-
version (Windows)
842-
return buildNormalizedPath(redubEnv["LOCALAPPDATA"], "dub");
842+
static string dubWorkspace;
843+
if(dubWorkspace.length)
844+
return dubWorkspace;
845+
846+
version(Windows)
847+
string home = "LOCALAPPDATA";
843848
else
844-
return buildNormalizedPath(redubEnv["HOME"], ".dub");
849+
string home = "HOME";
850+
851+
string dPath = getEnvVariable("DPATH");
852+
853+
string customHome;
854+
if(dPath)
855+
{
856+
customHome = getEnvVariable("DUB_HOME");
857+
if(!isAbsolute(customHome))
858+
throw new RedubException("DUB_HOME must not be an absolute path '"~customHome~"' when DPATH is defined ["~dPath~"]");
859+
home = buildNormalizedPath(dPath, getEnvVariable("DUB_HOME"));
860+
}
861+
else
862+
{
863+
customHome = getEnvVariable("DUB_HOME");
864+
if(customHome)
865+
home = customHome;
866+
else
867+
home = getEnvVariable(home);
868+
}
869+
return dubWorkspace = buildNormalizedPath(home, ".dub");
845870
}
846871

847872

source/redub/extensions/update.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int updateMain(string[] args)
5858
{
5959
auto ret = execute(["git", "pull"], null, Config.none, size_t.max, redubPath);
6060
gitCode = ret.status;
61+
6162
if(gitCode != 0 && gitCode != isNotGitRepo)
6263
{
6364
errorTitle("Git Pull Error: \n", ret.output);
@@ -70,7 +71,7 @@ int updateMain(string[] args)
7071
}
7172
}
7273

73-
if(gitCode == isNotGitRepo || hasGit)
74+
if(gitCode == isNotGitRepo || !hasGit)
7475
{
7576
import d_downloader;
7677
latest = getLatestRedubVersion();

source/redub/package_searching/dub.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ void prefetchPackages(string dubSelectionsPath)
275275
private string getDefaultLookupPathForPackages()
276276
{
277277
import redub.misc.path;
278-
return buildNormalizedPath(getDubWorkspacePath, "packages");
278+
static string defaultPath;
279+
if(!defaultPath)
280+
defaultPath = buildNormalizedPath(getDubWorkspacePath, "packages");
281+
return defaultPath;
279282
}
280283

281284
private string getLocalPackagesPath()

0 commit comments

Comments
 (0)