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