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 FileUtil.createSymLink(linkName, tempFile.getPath());
172 supportSymlinks = Boolean.TRUE;
173 linkName.delete();
174 } catch (IOException | UnsupportedOperationException e) {
175 supportSymlinks = Boolean.FALSE;
176 } finally {
177 if (tempFile != null)
178 try {
179 FileUtils.delete(tempFile);
180 } catch (IOException e) {
181 throw new RuntimeException(e);
182 }
183 }
184 }
185
186 @Override
187 public boolean isSymLink(File path) throws IOException {
188 return FileUtil.isSymlink(path);
189 }
190
191 @Override
192 public long lastModified(File path) throws IOException {
193 return FileUtil.lastModified(path);
194 }
195
196 @Override
197 public void setLastModified(File path, long time) throws IOException {
198 FileUtil.setLastModified(path, time);
199 }
200
201 @Override
202 public void delete(File path) throws IOException {
203 FileUtil.delete(path);
204 }
205
206 @Override
207 public long length(File f) throws IOException {
208 return FileUtil.getLength(f);
209 }
210
211 @Override
212 public boolean exists(File path) {
213 return FileUtil.exists(path);
214 }
215
216 @Override
217 public boolean isDirectory(File path) {
218 return FileUtil.isDirectory(path);
219 }
220
221 @Override
222 public boolean isFile(File path) {
223 return FileUtil.isFile(path);
224 }
225
226 @Override
227 public boolean isHidden(File path) throws IOException {
228 return FileUtil.isHidden(path);
229 }
230
231 @Override
232 public void setHidden(File path, boolean hidden) throws IOException {
233 FileUtil.setHidden(path, hidden);
234 }
235
236 @Override
237 public String readSymLink(File path) throws IOException {
238 return FileUtil.readSymlink(path);
239 }
240
241 @Override
242 public void createSymLink(File path, String target) throws IOException {
243 FileUtil.createSymLink(path, target);
244 }
245
246
247
248
249 @Override
250 public Attributes getAttributes(File path) {
251 return FileUtil.getFileAttributesBasic(this, path);
252 }
253 }