import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.jgit.util.io.AutoCRLFOutputStream;
void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i,
WorkingTreeIterator f) throws IOException {
if (m != null) {
- if (!isValidPath(m))
- throw new InvalidPathException(m.getEntryPathString());
+ checkValidPath(m);
// There is an entry in the merge commit. Means: we want to update
// what's currently in the index and working-tree to that one
if (i == null) {
String name = walk.getPathString();
- if (m != null && !isValidPath(m))
- throw new InvalidPathException(m.getEntryPathString());
+ if (m != null)
+ checkValidPath(m);
if (i == null && m == null && h == null) {
// File/Directory conflict case #20
forbidden[i] = Constants.encodeASCII(list[i]);
}
- private static boolean isValidPath(CanonicalTreeParser t) {
+ private static void checkValidPath(CanonicalTreeParser t)
+ throws InvalidPathException {
for (CanonicalTreeParser i = t; i != null; i = i.getParent())
- if (!isValidPathSegment(i))
- return false;
- return true;
+ checkValidPathSegment(i);
}
- private static boolean isValidPathSegment(CanonicalTreeParser t) {
+ private static void checkValidPathSegment(CanonicalTreeParser t)
+ throws InvalidPathException {
boolean isWindows = SystemReader.getInstance().isWindows();
boolean isOSX = SystemReader.getInstance().isMacOS();
boolean ignCase = isOSX || isWindows;
int start = ptr;
while (ptr < end) {
if (raw[ptr] == '/')
- return false;
+ throw new InvalidPathException(
+ JGitText.get().invalidPathContainsSeparator,
+ "/", t.getEntryPathString()); //$NON-NLS-1$
if (isWindows) {
if (raw[ptr] == '\\')
- return false;
+ throw new InvalidPathException(
+ JGitText.get().invalidPathContainsSeparator,
+ "\\", t.getEntryPathString()); //$NON-NLS-1$
if (raw[ptr] == ':')
- return false;
+ throw new InvalidPathException(
+ JGitText.get().invalidPathContainsSeparator,
+ ":", t.getEntryPathString()); //$NON-NLS-1$
}
ptr++;
}
- // '.' and '.'' are invalid here
+ // '.' and '..' are invalid here
if (ptr - start == 1) {
if (raw[start] == '.')
- return false;
+ throw new InvalidPathException(t.getEntryPathString());
} else if (ptr - start == 2) {
if (raw[start] == '.')
if (raw[start + 1] == '.')
- return false;
+ throw new InvalidPathException(t.getEntryPathString());
} else if (ptr - start == 4) {
// .git (possibly case insensitive) is disallowed
if (raw[start] == '.')
|| (ignCase && raw[start + 2] == 'I'))
if (raw[start + 3] == 't'
|| (ignCase && raw[start + 3] == 'T'))
- return false;
+ throw new InvalidPathException(
+ t.getEntryPathString());
}
if (isWindows) {
// Space or period at end of file name is ignored by Windows.
// Treat this as a bad path for now. We may want to handle
// this as case insensitivity in the future.
- if (ptr > 0)
- if (raw[ptr - 1] == '.' || raw[ptr - 1] == ' ')
- return false;
+ if (ptr > 0) {
+ if (raw[ptr - 1] == '.')
+ throw new InvalidPathException(
+ JGitText.get().invalidPathPeriodAtEndWindows,
+ t.getEntryPathString());
+ if (raw[ptr - 1] == ' ')
+ throw new InvalidPathException(
+ JGitText.get().invalidPathSpaceAtEndWindows,
+ t.getEntryPathString());
+ }
+
int i;
// Bad names, eliminate suffix first
for (i = start; i < ptr; ++i)
break;
}
if (k == len)
- return false;
+ throw new InvalidPathException(
+ JGitText.get().invalidPathReservedOnWindows,
+ RawParseUtils.decode(forbidden[j]), t
+ .getEntryPathString());
}
}
}
}
-
- return true;
}
private static byte toUpper(byte b) {