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 import org.eclipse.jgit.errors.CommandFailedException;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57
58
59
60
61
62
63
64 public class FS_Win32 extends FS {
65 private final static Logger LOG = LoggerFactory.getLogger(FS_Win32.class);
66
67 private volatile Boolean supportSymlinks;
68
69
70
71
72 public FS_Win32() {
73 super();
74 }
75
76
77
78
79
80
81
82 protected FS_Win32(FS src) {
83 super(src);
84 }
85
86
87 @Override
88 public FS newInstance() {
89 return new FS_Win32(this);
90 }
91
92
93 @Override
94 public boolean supportsExecute() {
95 return false;
96 }
97
98
99 @Override
100 public boolean canExecute(final File f) {
101 return false;
102 }
103
104
105 @Override
106 public boolean setExecute(final File f, final boolean canExec) {
107 return false;
108 }
109
110
111 @Override
112 public boolean isCaseSensitive() {
113 return false;
114 }
115
116
117 @Override
118 public boolean retryFailedLockFileCommit() {
119 return true;
120 }
121
122
123 @Override
124 protected File discoverGitExe() {
125 String path = SystemReader.getInstance().getenv("PATH");
126 File gitExe = searchPath(path, "git.exe", "git.cmd");
127
128 if (gitExe == null) {
129 if (searchPath(path, "bash.exe") != null) {
130
131
132 String w;
133 try {
134 w = readPipe(userHome(),
135 new String[]{"bash", "--login", "-c", "which git"},
136 Charset.defaultCharset().name());
137 } catch (CommandFailedException e) {
138 LOG.warn(e.getMessage());
139 return null;
140 }
141 if (!StringUtils.isEmptyOrNull(w)) {
142
143 gitExe = resolve(null, w);
144 }
145 }
146 }
147
148 return gitExe;
149 }
150
151
152 @Override
153 protected File userHomeImpl() {
154 String home = SystemReader.getInstance().getenv("HOME");
155 if (home != null)
156 return resolve(null, home);
157 String homeDrive = SystemReader.getInstance().getenv("HOMEDRIVE");
158 if (homeDrive != null) {
159 String homePath = SystemReader.getInstance().getenv("HOMEPATH");
160 if (homePath != null)
161 return new File(homeDrive, homePath);
162 }
163
164 String homeShare = SystemReader.getInstance().getenv("HOMESHARE");
165 if (homeShare != null)
166 return new File(homeShare);
167
168 return super.userHomeImpl();
169 }
170
171
172 @Override
173 public ProcessBuilder runInShell(String cmd, String[] args) {
174 List<String> argv = new ArrayList<>(3 + args.length);
175 argv.add("cmd.exe");
176 argv.add("/c");
177 argv.add(cmd);
178 argv.addAll(Arrays.asList(args));
179 ProcessBuilder proc = new ProcessBuilder();
180 proc.command(argv);
181 return proc;
182 }
183
184
185 @Override
186 public boolean supportsSymlinks() {
187 if (supportSymlinks == null)
188 detectSymlinkSupport();
189 return Boolean.TRUE.equals(supportSymlinks);
190 }
191
192 private void detectSymlinkSupport() {
193 File tempFile = null;
194 try {
195 tempFile = File.createTempFile("tempsymlinktarget", "");
196 File linkName = new File(tempFile.getParentFile(), "tempsymlink");
197 createSymLink(linkName, tempFile.getPath());
198 supportSymlinks = Boolean.TRUE;
199 linkName.delete();
200 } catch (IOException | UnsupportedOperationException
201 | InternalError e) {
202 supportSymlinks = Boolean.FALSE;
203 } finally {
204 if (tempFile != null)
205 try {
206 FileUtils.delete(tempFile);
207 } catch (IOException e) {
208 throw new RuntimeException(e);
209 }
210 }
211 }
212
213
214 @Override
215 public Attributes getAttributes(File path) {
216 return FileUtils.getFileAttributesBasic(this, path);
217 }
218 }