diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2009-09-11 12:33:05 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-02-03 19:58:20 -0800 |
commit | 29b8fa84e680ce090ed355afd6052c4be9137a0c (patch) | |
tree | fe7cb5afcd2272d1c7bdbd89e6d0167d92e34c12 /org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java | |
parent | 329abf721214f60077c9b17cc2c4235bdeed2c4f (diff) | |
download | jgit-29b8fa84e680ce090ed355afd6052c4be9137a0c.tar.gz jgit-29b8fa84e680ce090ed355afd6052c4be9137a0c.zip |
Don't allow DirCacheEntry with mode of 0
A 0 file mode in a DirCacheEntry is not a valid mode. To C git
such a value indicates the record should not be present. We already
were catching this bad state and exceptioning out when writing tree
objects to disk, but we did not fail when writing the dircache back
to disk. This allowed JGit applications to create a dircache file
which C git would not like to read.
Instead of checking the mode during writes, we now check during
mutation. This allows application bugs to be detected sooner and
closer to the cause site. It also allows us to avoid checking most
of the records which we read in from disk, as we can assume these
are formatted correctly.
Some of our unit tests were not setting the FileMode on their test
entry, so they had to be updated to use REGULAR_FILE.
Change-Id: Ie412053c390b737c0ece57b8e063e4355ee32437
Originally: http://thread.gmane.org/gmane.comp.version-control.git/128214/focus=128213
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
CC: Adam W. Hawks <awhawks@writeme.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index eed33401d5..415de095b2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -388,8 +388,18 @@ public class DirCacheEntry { * * @param mode * the new mode constant. + * @throws IllegalArgumentException + * If {@code mode} is {@link FileMode#MISSING}, + * {@link FileMode#TREE}, or any other type code not permitted + * in a tree object. */ public void setFileMode(final FileMode mode) { + switch (mode.getBits() & FileMode.TYPE_MASK) { + case FileMode.TYPE_MISSING: + case FileMode.TYPE_TREE: + throw new IllegalArgumentException("Invalid mode " + mode + + " for path " + getPathString()); + } NB.encodeInt32(info, infoOffset + P_MODE, mode.getBits()); } |