* object reader to use for checkout
* @throws IOException
*/
public static void checkoutEntry(final Repository repo, File f,
DirCacheEntry entry, ObjectReader or) throws IOException {
ObjectLoader ol = or.open(entry.getObjectId());
File parentDir = f.getParentFile();
File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
FileOutputStream rawChannel = new FileOutputStream(tmpFile);
OutputStream channel;
if (opt.getAutoCRLF() == AutoCRLF.TRUE)
channel = new AutoCRLFOutputStream(rawChannel);
else
channel = rawChannel;
try {
ol.copyTo(channel);
} finally {
channel.close();
}
FS fs = repo.getFS();
if (opt.isFileMode() && fs.supportsExecute()) {
if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) {
if (!fs.canExecute(tmpFile))
fs.setExecute(tmpFile, true);
} else {
if (fs.canExecute(tmpFile))
fs.setExecute(tmpFile, false);
}
}
if (!tmpFile.renameTo(f)) {
// tried to rename which failed. Let' delete the target file and try
// again
FileUtils.delete(f);
if (!tmpFile.renameTo(f)) {
throw new IOException(MessageFormat.format(
JGitText.get().couldNotWriteFile, tmpFile.getPath(),
f.getPath()));
}
}
entry.setLastModified(f.lastModified());
if (opt.getAutoCRLF() != AutoCRLF.FALSE)
entry.setLength(f.length()); // AutoCRLF wants on-disk-size
else
entry.setLength((int) ol.getSize());
}