IDEA-26980 (consider .jar length when updating mirror file)

Problem: Apply Patch action (which adds .jar file to a .jar directory) in a course of applicability check creates empty files in VFS. This triggers following event chain: VFS create file -> .jar directory update -> project root update -> .jar scan -> mirror file update, and leads to copying 0-length content into a .jar mirror. Subsequent VFS content change event doesn't caused mirror update as it usually takes less then 2 secs to apply patch completely.
This commit is contained in:
Roman Shevchenko
2012-09-06 20:13:00 +04:00
parent 76868d93ea
commit 228c172c32
@@ -25,6 +25,8 @@ import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileAttributes;
import com.intellij.openapi.util.io.FileSystemUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -70,22 +72,27 @@ public class JarHandler extends JarHandlerBase implements FileSystemInterface {
@Override
public File getMirrorFile(File originalFile) {
if (!myFileSystem.isMakeCopyOfJar(originalFile) || !originalFile.exists()) return originalFile;
if (!myFileSystem.isMakeCopyOfJar(originalFile)) return originalFile;
String folderPath = getJarsDir();
final FileAttributes originalAttributes = FileSystemUtil.getAttributes(originalFile);
if (originalAttributes == null) return originalFile;
final String folderPath = getJarsDir();
if (!new File(folderPath).exists() && !new File(folderPath).mkdirs()) {
return originalFile;
}
String fileName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode());
File mirror = new File(folderPath, fileName);
final String mirrorName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode());
final File mirrorFile = new File(folderPath, mirrorName);
final FileAttributes mirrorAttributes = FileSystemUtil.getAttributes(mirrorFile);
if (!mirror.exists() ||
Math.abs(originalFile.lastModified() - mirror.lastModified()) > 2000) {
return copyToMirror(originalFile, mirror);
if (mirrorAttributes == null ||
originalAttributes.length != mirrorAttributes.length ||
Math.abs(originalAttributes.lastModified - mirrorAttributes.lastModified) > 2000) {
return copyToMirror(originalFile, mirrorFile);
}
return mirror;
return mirrorFile;
}
private static String getJarsDir() {