* the entry containing new mode and content
* @throws IOException
*/
public static void checkoutEntry(final Repository repo, File f,
DirCacheEntry entry) throws IOException {
ObjectLoader ol = repo.open(entry.getObjectId());
File parentDir = f.getParentFile();
File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
FileOutputStream channel = new FileOutputStream(tmpFile);
try {
ol.copyTo(channel);
} finally {
channel.close();
}
FS fs = repo.getFS();
WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
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());
entry.setLength((int) ol.getSize());
}