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