[diff] Fix extension, don't treat empty file as text

* Add "." to the temp file suffix to produce the file extension.
* Don't treat any empty file as text with stub content:
  let it have the same type as detected by extension. This will show
  "Image can't be loaded" warning, for an empty jpg file, for example,
  but it is expected behavior.
  This doesn't affect ADDED changes: they don't have before revision
  at all and don't create FileContent for them.
This commit is contained in:
Kirill Likhodedov
2013-02-21 12:38:34 +04:00
parent 7878527d98
commit 969ba5cc52
@@ -82,12 +82,8 @@ public class FileContent extends DiffContent {
}
public static FileContent createFromTempFile(Project project, String name, String ext, @NotNull byte[] content) throws IOException {
final File tempFile;
if (content.length == 0) {
tempFile = FileUtil.createTempFile(name, "txt");
FileUtil.writeToFile(tempFile, "Does not exist");
} else {
tempFile = FileUtil.createTempFile(name, ext);
File tempFile = FileUtil.createTempFile(name, "." + ext);
if (content.length != 0) {
FileUtil.writeToFile(tempFile, content);
}
tempFile.deleteOnExit();