1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 package org.eclipse.jgit.util;
46
47 import java.io.File;
48 import java.io.IOException;
49 import java.nio.charset.Charset;
50 import java.util.ArrayList;
51 import java.util.Arrays;
52 import java.util.List;
53
54
55
56
57
58
59
60 public class FS_Win32 extends FS {
61
62 private volatile Boolean supportSymlinks;
63
64
65
66
67 public FS_Win32() {
68 super();
69 }
70
71
72
73
74
75
76
77 protected FS_Win32(FS src) {
78 super(src);
79 }
80
81 public FS newInstance() {
82 return new FS_Win32(this);
83 }
84
85 public boolean supportsExecute() {
86 return false;
87 }
88
89 public boolean canExecute(final File f) {
90 return false;
91 }
92
93 public boolean setExecute(final File f, final boolean canExec) {
94 return false;
95 }
96
97 @Override
98 public boolean isCaseSensitive() {
99 return false;
100 }
101
102 @Override
103 public boolean retryFailedLockFileCommit() {
104 return true;
105 }
106
107 @Override
108 protected File discoverGitExe() {
109 String path = SystemReader.getInstance().getenv("PATH");
110 File gitExe = searchPath(path, "git.exe", "git.cmd");
111
112 if (gitExe == null) {
113 if (searchPath(path, "bash.exe") != null) {
114
115
116 String w = readPipe(userHome(),
117 new String[]{"bash", "--login", "-c", "which git"},
118 Charset.defaultCharset().name());
119 if (!StringUtils.isEmptyOrNull(w))
120
121 gitExe = resolve(null, w);
122 }
123 }
124
125 return gitExe;
126 }
127
128 @Override
129 protected File userHomeImpl() {
130 String home = SystemReader.getInstance().getenv("HOME");
131 if (home != null)
132 return resolve(null, home);
133 String homeDrive = SystemReader.getInstance().getenv("HOMEDRIVE");
134 if (homeDrive != null) {
135 String homePath = SystemReader.getInstance().getenv("HOMEPATH");
136 if (homePath != null)
137 return new File(homeDrive, homePath);
138 }
139
140 String homeShare = SystemReader.getInstance().getenv("HOMESHARE");
141 if (homeShare != null)
142 return new File(homeShare);
143
144 return super.userHomeImpl();
145 }
146
147 @Override
148 public ProcessBuilder runInShell(String cmd, String[] args) {
149 List<String> argv = new ArrayList<String>(3 + args.length);
150 argv.add("cmd.exe");
151 argv.add("/c");
152 argv.add(cmd);
153 argv.addAll(Arrays.asList(args));
154 ProcessBuilder proc = new ProcessBuilder();
155 proc.command(argv);
156 return proc;
157 }
158
159 @Override
160 public boolean supportsSymlinks() {
161 if (supportSymlinks == null)
162 detectSymlinkSupport();
163 return Boolean.TRUE.equals(supportSymlinks);
164 }
165
166 private void detectSymlinkSupport() {
167 File tempFile = null;
168 try {
169 tempFile = File.createTempFile("tempsymlinktarget", "");
170 File linkName = new File(tempFile.getParentFile(), "tempsymlink");
171 createSymLink(linkName, tempFile.getPath());
172 supportSymlinks = Boolean.TRUE;
173 linkName.delete();
174 } catch (IOException | UnsupportedOperationException
175 | InternalError e) {
176 supportSymlinks = Boolean.FALSE;
177 } finally {
178 if (tempFile != null)
179 try {
180 FileUtils.delete(tempFile);
181 } catch (IOException e) {
182 throw new RuntimeException(e);
183 }
184 }
185 }
186
187
188
189
190 @Override
191 public Attributes getAttributes(File path) {
192 return FileUtils.getFileAttributesBasic(this, path);
193 }
194 }