expand ~ in WORKON_HOME (PY-10336)

This commit is contained in:
Dmitry Jemerov
2013-10-31 15:43:17 +01:00
parent 74d8bc04e4
commit 42f4d0f6f8
3 changed files with 10 additions and 5 deletions
@@ -416,9 +416,7 @@ public class PathManager {
// helpers
private static String getAbsolutePath(String path) {
if (path.startsWith("~/") || path.startsWith("~\\")) {
path = getUserHome() + path.substring(1);
}
path = FileUtil.expandUserHome(path);
return new File(path).getAbsolutePath();
}
@@ -1213,6 +1213,13 @@ public class FileUtil extends FileUtilRt {
return path;
}
public static String expandUserHome(String path) {
if (path.startsWith("~/") || path.startsWith("~\\")) {
path = SystemProperties.getUserHome() + path.substring(1);
}
return path;
}
@NotNull
public static File[] notNullize(@Nullable File[] files) {
return notNullize(files, ArrayUtil.EMPTY_FILE_ARRAY);
@@ -17,9 +17,9 @@ package com.jetbrains.python.sdk.flavors;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -67,7 +67,7 @@ public class VirtualEnvSdkFlavor extends CPythonSdkFlavor {
public static VirtualFile getDefaultLocation() {
final String path = System.getenv().get("WORKON_HOME");
if (!StringUtil.isEmpty(path)) {
return LocalFileSystem.getInstance().findFileByPath(path.replace('\\','/'));
return LocalFileSystem.getInstance().findFileByPath(FileUtil.expandUserHome(path).replace('\\','/'));
}
final VirtualFile userHome = LocalFileSystem.getInstance().findFileByPath(SystemProperties.getUserHome().replace('\\','/'));