Bug 521753 - Exceptions thrown by DirCacheCheckout when cloning on Windows network folders.
Summary: Exceptions thrown by DirCacheCheckout when cloning on Windows network folders.
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 10
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-01 09:17 EDT by Tim Hosey CLA
Modified: 2017-09-01 09:17 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hosey CLA 2017-09-01 09:17:47 EDT
In Windows when cloning to a network folder location, DirCacheCheckout can under certain circumstances throw an exception because of the way it constructs temp files.

We have encountered network folders on Windows where files that start with the . character are being reported as hidden by java.io.File.

When this happens DirCacheCheckout's checkoutEntry method will always throw an exception because the temp file that is created starts with a . character and new FileOutputStream(tmpFile) throws an exception when called on a hidden file (http://bugs.java.com/view_bug.do?bug_id=6401006).

I would like to suggest two possible fixes that can be made to DirCacheCheckout to fix this problem.

(https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java)

tmpFile could be made to not start with a . character:

File tmpFile = File.createTempFile(
				"._" + name, null, parentDir); //$NON-NLS-1$
becomes something like 

File tmpFile = File.createTempFile(
				"x_" + name, null, parentDir); //$NON-NLS-1$

As this file is a new temp file, another possibility would be to create the FileOutputStream of tmpFile using the append true flag. Unlike the default constructor, this way of constructing the FileOutputStream will not result in an exception being thrown even if the file is hidden.

try (OutputStream channel = EolStreamTypeUtil.wrapOutputStream(
new FileOutputStream(tmpFile), nonNullEolStreamType)) {

could be changed to 

try (OutputStream channel = EolStreamTypeUtil.wrapOutputStream(
new FileOutputStream(tmpFile, true), nonNullEolStreamType)) {