1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.util;
13
14 import java.io.File;
15 import java.io.IOException;
16 import java.nio.charset.Charset;
17 import java.nio.file.FileVisitOption;
18 import java.nio.file.FileVisitResult;
19 import java.nio.file.Files;
20 import java.nio.file.Path;
21 import java.nio.file.SimpleFileVisitor;
22 import java.nio.file.attribute.BasicFileAttributes;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.EnumSet;
26 import java.util.List;
27
28 import org.eclipse.jgit.errors.CommandFailedException;
29 import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry;
30 import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy;
31 import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36
37
38
39
40
41 public class FS_Win32 extends FS {
42 private static final Logger LOG = LoggerFactory.getLogger(FS_Win32.class);
43
44
45
46
47 public FS_Win32() {
48 super();
49 }
50
51
52
53
54
55
56
57 protected FS_Win32(FS src) {
58 super(src);
59 }
60
61
62 @Override
63 public FS newInstance() {
64 return new FS_Win32(this);
65 }
66
67
68 @Override
69 public boolean supportsExecute() {
70 return false;
71 }
72
73
74 @Override
75 public boolean canExecute(File f) {
76 return false;
77 }
78
79
80 @Override
81 public boolean setExecute(File f, boolean canExec) {
82 return false;
83 }
84
85
86 @Override
87 public boolean isCaseSensitive() {
88 return false;
89 }
90
91
92 @Override
93 public boolean retryFailedLockFileCommit() {
94 return true;
95 }
96
97
98 @Override
99 public Entry[] list(File directory, FileModeStrategy fileModeStrategy) {
100 List<Entry> result = new ArrayList<>();
101 FS fs = this;
102 boolean checkExecutable = fs.supportsExecute();
103 try {
104 Files.walkFileTree(directory.toPath(),
105 EnumSet.noneOf(FileVisitOption.class), 1,
106 new SimpleFileVisitor<Path>() {
107 @Override
108 public FileVisitResult visitFile(Path file,
109 BasicFileAttributes attrs) throws IOException {
110 File f = file.toFile();
111 FS.Attributes attributes = new FS.Attributes(fs, f,
112 true, attrs.isDirectory(),
113 checkExecutable && f.canExecute(),
114 attrs.isSymbolicLink(),
115 attrs.isRegularFile(),
116 attrs.creationTime().toMillis(),
117 attrs.lastModifiedTime().toInstant(),
118 attrs.size());
119 result.add(new FileEntry(f, fs, attributes,
120 fileModeStrategy));
121 return FileVisitResult.CONTINUE;
122 }
123
124 @Override
125 public FileVisitResult visitFileFailed(Path file,
126 IOException exc) throws IOException {
127
128 return FileVisitResult.CONTINUE;
129 }
130 });
131 } catch (IOException e) {
132
133 }
134 if (result.isEmpty()) {
135 return NO_ENTRIES;
136 }
137 return result.toArray(new Entry[0]);
138 }
139
140
141 @Override
142 protected File discoverGitExe() {
143 String path = SystemReader.getInstance().getenv("PATH");
144 File gitExe = searchPath(path, "git.exe", "git.cmd");
145
146 if (gitExe == null) {
147 if (searchPath(path, "bash.exe") != null) {
148
149
150 String w;
151 try {
152 w = readPipe(userHome(),
153 new String[]{"bash", "--login", "-c", "which git"},
154 Charset.defaultCharset().name());
155 } catch (CommandFailedException e) {
156 LOG.warn(e.getMessage());
157 return null;
158 }
159 if (!StringUtils.isEmptyOrNull(w)) {
160
161 gitExe = resolve(null, w);
162 }
163 }
164 }
165
166 return gitExe;
167 }
168
169
170 @Override
171 protected File userHomeImpl() {
172 String home = SystemReader.getInstance().getenv("HOME");
173 if (home != null) {
174 return resolve(null, home);
175 }
176 String homeDrive = SystemReader.getInstance().getenv("HOMEDRIVE");
177 if (homeDrive != null) {
178 String homePath = SystemReader.getInstance().getenv("HOMEPATH");
179 if (homePath != null) {
180 return new File(homeDrive, homePath);
181 }
182 }
183
184 String homeShare = SystemReader.getInstance().getenv("HOMESHARE");
185 if (homeShare != null) {
186 return new File(homeShare);
187 }
188
189 return super.userHomeImpl();
190 }
191
192
193 @Override
194 public ProcessBuilder runInShell(String cmd, String[] args) {
195 List<String> argv = new ArrayList<>(3 + args.length);
196 argv.add("cmd.exe");
197 argv.add("/c");
198 argv.add(cmd);
199 argv.addAll(Arrays.asList(args));
200 ProcessBuilder proc = new ProcessBuilder();
201 proc.command(argv);
202 return proc;
203 }
204
205
206 @Override
207 public Attributes getAttributes(File path) {
208 return FileUtils.getFileAttributesBasic(this, path);
209 }
210 }