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.nio.file.FileVisitOption;
51 import java.nio.file.FileVisitResult;
52 import java.nio.file.Files;
53 import java.nio.file.Path;
54 import java.nio.file.SimpleFileVisitor;
55 import java.nio.file.attribute.BasicFileAttributes;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.EnumSet;
59 import java.util.List;
60
61 import org.eclipse.jgit.errors.CommandFailedException;
62 import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry;
63 import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy;
64 import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68
69
70
71
72
73
74 public class FS_Win32 extends FS {
75 private final static Logger LOG = LoggerFactory.getLogger(FS_Win32.class);
76
77
78
79
80 public FS_Win32() {
81 super();
82 }
83
84
85
86
87
88
89
90 protected FS_Win32(FS src) {
91 super(src);
92 }
93
94
95 @Override
96 public FS newInstance() {
97 return new FS_Win32(this);
98 }
99
100
101 @Override
102 public boolean supportsExecute() {
103 return false;
104 }
105
106
107 @Override
108 public boolean canExecute(File f) {
109 return false;
110 }
111
112
113 @Override
114 public boolean setExecute(File f, boolean canExec) {
115 return false;
116 }
117
118
119 @Override
120 public boolean isCaseSensitive() {
121 return false;
122 }
123
124
125 @Override
126 public boolean retryFailedLockFileCommit() {
127 return true;
128 }
129
130
131 @Override
132 public Entry[] list(File directory, FileModeStrategy fileModeStrategy) {
133 List<Entry> result = new ArrayList<>();
134 FS fs = this;
135 boolean checkExecutable = fs.supportsExecute();
136 try {
137 Files.walkFileTree(directory.toPath(),
138 EnumSet.noneOf(FileVisitOption.class), 1,
139 new SimpleFileVisitor<Path>() {
140 @Override
141 public FileVisitResult visitFile(Path file,
142 BasicFileAttributes attrs) throws IOException {
143 File f = file.toFile();
144 FS.Attributes attributes = new FS.Attributes(fs, f,
145 true, attrs.isDirectory(),
146 checkExecutable && f.canExecute(),
147 attrs.isSymbolicLink(),
148 attrs.isRegularFile(),
149 attrs.creationTime().toMillis(),
150 attrs.lastModifiedTime().toInstant(),
151 attrs.size());
152 result.add(new FileEntry(f, fs, attributes,
153 fileModeStrategy));
154 return FileVisitResult.CONTINUE;
155 }
156
157 @Override
158 public FileVisitResult visitFileFailed(Path file,
159 IOException exc) throws IOException {
160
161 return FileVisitResult.CONTINUE;
162 }
163 });
164 } catch (IOException e) {
165
166 }
167 if (result.isEmpty()) {
168 return NO_ENTRIES;
169 }
170 return result.toArray(new Entry[0]);
171 }
172
173
174 @Override
175 protected File discoverGitExe() {
176 String path = SystemReader.getInstance().getenv("PATH");
177 File gitExe = searchPath(path, "git.exe", "git.cmd");
178
179 if (gitExe == null) {
180 if (searchPath(path, "bash.exe") != null) {
181
182
183 String w;
184 try {
185 w = readPipe(userHome(),
186 new String[]{"bash", "--login", "-c", "which git"},
187 Charset.defaultCharset().name());
188 } catch (CommandFailedException e) {
189 LOG.warn(e.getMessage());
190 return null;
191 }
192 if (!StringUtils.isEmptyOrNull(w)) {
193
194 gitExe = resolve(null, w);
195 }
196 }
197 }
198
199 return gitExe;
200 }
201
202
203 @Override
204 protected File userHomeImpl() {
205 String home = SystemReader.getInstance().getenv("HOME");
206 if (home != null) {
207 return resolve(null, home);
208 }
209 String homeDrive = SystemReader.getInstance().getenv("HOMEDRIVE");
210 if (homeDrive != null) {
211 String homePath = SystemReader.getInstance().getenv("HOMEPATH");
212 if (homePath != null) {
213 return new File(homeDrive, homePath);
214 }
215 }
216
217 String homeShare = SystemReader.getInstance().getenv("HOMESHARE");
218 if (homeShare != null) {
219 return new File(homeShare);
220 }
221
222 return super.userHomeImpl();
223 }
224
225
226 @Override
227 public ProcessBuilder runInShell(String cmd, String[] args) {
228 List<String> argv = new ArrayList<>(3 + args.length);
229 argv.add("cmd.exe");
230 argv.add("/c");
231 argv.add(cmd);
232 argv.addAll(Arrays.asList(args));
233 ProcessBuilder proc = new ProcessBuilder();
234 proc.command(argv);
235 return proc;
236 }
237
238
239 @Override
240 public Attributes getAttributes(File path) {
241 return FileUtils.getFileAttributesBasic(this, path);
242 }
243 }