C: fix File.mkdirs() on Windows

This commit is contained in:
Alexey Andreev 2019-07-11 18:06:15 +03:00
parent cdcaa8947c
commit 9ad0ddd891
3 changed files with 33 additions and 12 deletions

View File

@ -36,7 +36,8 @@ public class CVirtualFile implements VirtualFile {
@Override @Override
public String getName() { public String getName() {
return path.substring(path.lastIndexOf('/') + 1); char separatorChar = fileSystem.isWindows() ? '\\' : '/';
return path.substring(path.lastIndexOf(separatorChar) + 1);
} }
@Override @Override
@ -174,7 +175,10 @@ public class CVirtualFile implements VirtualFile {
return CFileSystem.length(chars, chars.length); return CFileSystem.length(chars, chars.length);
} }
private static String constructPath(String parent, String child) { private String constructPath(String parent, String child) {
return parent.endsWith("/") ? parent + child : parent + "/" + child; char separatorChar = fileSystem.isWindows() ? '\\' : '/';
return !parent.isEmpty() && parent.charAt(parent.length() - 1) == separatorChar
? parent + child
: parent + separatorChar + child;
} }
} }

View File

@ -411,25 +411,37 @@ public class TFile implements Serializable, Comparable<TFile> {
public boolean mkdirs() { public boolean mkdirs() {
String path = getCanonicalPathImpl(); String path = getCanonicalPathImpl();
int i = path.indexOf(separatorChar); if (path.indexOf(separatorChar) < 0) {
if (i < 0) {
return false; return false;
} }
int i = path.length();
do {
VirtualFile file = fs().getFile(path.substring(0, i));
if (file.isDirectory()) {
break;
} else if (file.isFile()) {
return false;
}
i = path.lastIndexOf(separatorChar, i - 1);
} while (i >= 0);
i++; i++;
while (i < path.length()) { while (i < path.length()) {
int next = path.indexOf(separatorChar, i); int next = path.indexOf(separatorChar, i);
if (next < 0) { if (next < 0) {
next = path.length(); next = path.length();
} }
if (next == i + 1) {
break;
}
VirtualFile parent = fs().getFile(path.substring(0, i)); VirtualFile file = fs().getFile(path.substring(0, i));
if (!parent.createDirectory(path.substring(i, next))) { if (!file.createDirectory(path.substring(i, next))) {
VirtualFile child = fs().getFile(path.substring(0, next));
if (!child.isDirectory()) {
return false; return false;
} }
}
i = next + 1; i = next + 1;
} }

View File

@ -119,6 +119,11 @@ class CRunStrategy implements TestRunStrategy {
} }
lines.add(line); lines.add(line);
stdout.add(line); stdout.add(line);
if (lines.size() > 10000) {
output.addAll(lines);
process.destroy();
return false;
}
} }
} catch (IOException e) { } catch (IOException e) {
// do nothing // do nothing