use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.
the class CompilerUtil method refreshOutputRoots.
/**
* A lightweight procedure which ensures that given roots exist in the VFS.
* No actual refresh is performed.
*/
public static void refreshOutputRoots(@NotNull Collection<String> outputRoots) {
LocalFileSystem fs = LocalFileSystem.getInstance();
Collection<VirtualFile> toRefresh = ContainerUtil.newHashSet();
for (String outputRoot : outputRoots) {
FileAttributes attributes = FileSystemUtil.getAttributes(FileUtil.toSystemDependentName(outputRoot));
VirtualFile vFile = fs.findFileByPath(outputRoot);
if (attributes != null && vFile == null) {
VirtualFile parent = fs.refreshAndFindFileByPath(PathUtil.getParentPath(outputRoot));
if (parent != null && toRefresh.add(parent)) {
parent.getChildren();
}
} else if (attributes == null && vFile != null || attributes != null && attributes.isDirectory() != vFile.isDirectory()) {
toRefresh.add(vFile);
}
}
if (!toRefresh.isEmpty()) {
RefreshQueue.getInstance().refresh(false, false, null, toRefresh);
}
}
use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.
the class JarFileSystemTest method testJarHandlerDoNotCreateCopyWhenListingArchive.
@Test
public void testJarHandlerDoNotCreateCopyWhenListingArchive() throws Exception {
File jar = IoTestUtil.createTestJar(tempDir.newFile("test.jar"));
JarHandler handler = new JarHandler(jar.getPath());
FileAttributes attributes = handler.getAttributes(JarFile.MANIFEST_NAME);
assertNotNull(attributes);
assertEquals(0, attributes.length);
assertTimestampsEqual(jar.lastModified(), attributes.lastModified);
if (((JarFileSystemImpl) JarFileSystem.getInstance()).isMakeCopyOfJar(jar)) {
// for performance reasons we create file copy on windows when we read contents and have the handle open to the copy
Field resolved = handler.getClass().getDeclaredField("myFileWithMirrorResolved");
resolved.setAccessible(true);
assertTrue(resolved.get(handler) == null);
}
}
use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.
the class LocalFileSystemTest method testWindowsHiddenDirectory.
public void testWindowsHiddenDirectory() throws Exception {
if (!SystemInfo.isWindows) {
System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME);
return;
}
File file = new File("C:\\Documents and Settings\\desktop.ini");
if (!file.exists()) {
System.err.println(getName() + " skipped: missing " + file);
return;
}
String parent = FileUtil.toSystemIndependentName(file.getParent());
VfsRootAccess.allowRootAccess(getTestRootDisposable(), parent);
VirtualFile virtualFile = myFS.refreshAndFindFileByIoFile(file);
assertNotNull(virtualFile);
NewVirtualFileSystem fs = (NewVirtualFileSystem) virtualFile.getFileSystem();
FileAttributes attributes = fs.getAttributes(virtualFile);
assertNotNull(attributes);
assertEquals(FileAttributes.Type.FILE, attributes.type);
assertEquals(FileAttributes.HIDDEN, attributes.flags);
}
use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.
the class JarHandler method getMirrorFile.
private File getMirrorFile(@NotNull File originalFile) {
if (!myFileSystem.isMakeCopyOfJar(originalFile))
return originalFile;
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;
}
if (FSRecords.weHaveContentHashes) {
return getMirrorWithContentHash(originalFile, originalAttributes);
}
final String mirrorName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode());
final File mirrorFile = new File(folderPath, mirrorName);
final FileAttributes mirrorAttributes = FileSystemUtil.getAttributes(mirrorFile);
return mirrorDiffers(originalAttributes, mirrorAttributes, false) ? copyToMirror(originalFile, mirrorFile) : mirrorFile;
}
use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.
the class JarHandler method getMirrorWithContentHash.
private File getMirrorWithContentHash(File originalFile, FileAttributes originalAttributes) {
File mirrorFile = null;
String jarDir = getJarsDir();
try {
String path = originalFile.getPath();
CacheLibraryInfo info = CacheLibraryInfo.ourCachedLibraryInfo.get(path);
if (info != null && originalAttributes.length == info.myFileLength && Math.abs(originalAttributes.lastModified - info.myModificationTime) <= FS_TIME_RESOLUTION) {
mirrorFile = new File(jarDir, info.mySnapshotPath);
if (!mirrorDiffers(originalAttributes, FileSystemUtil.getAttributes(mirrorFile), true)) {
return mirrorFile;
}
}
MessageDigest sha1;
File tempJarFile = null;
try {
tempJarFile = FileUtil.createTempFile(new File(jarDir), originalFile.getName(), "", true, false);
try (DataOutputStream os = new DataOutputStream(new FileOutputStream(tempJarFile));
FileInputStream is = new FileInputStream(originalFile)) {
sha1 = MessageDigest.getInstance("SHA1");
sha1.update(String.valueOf(originalAttributes.length).getBytes(Charset.defaultCharset()));
sha1.update((byte) 0);
byte[] buffer = new byte[8192];
long totalBytes = 0;
while (true) {
int read = is.read(buffer);
if (read < 0)
break;
totalBytes += read;
sha1.update(buffer, 0, read);
os.write(buffer, 0, read);
if (totalBytes == originalAttributes.length)
break;
}
}
} catch (IOException ex) {
File target = mirrorFile != null ? mirrorFile : tempJarFile != null ? tempJarFile : new File(jarDir);
reportIOErrorWithJars(originalFile, target, ex);
return originalFile;
} catch (NoSuchAlgorithmException ex) {
LOG.error(ex);
// should never happen for sha1
return originalFile;
}
String mirrorName = getSnapshotName(originalFile.getName(), sha1.digest());
mirrorFile = new File(jarDir, mirrorName);
FileAttributes mirrorFileAttributes = FileSystemUtil.getAttributes(mirrorFile);
if (mirrorFileAttributes == null) {
try {
FileUtil.rename(tempJarFile, mirrorFile);
FileUtil.setLastModified(mirrorFile, originalAttributes.lastModified);
} catch (IOException ex) {
reportIOErrorWithJars(originalFile, mirrorFile, ex);
return originalFile;
}
} else {
FileUtil.delete(tempJarFile);
}
info = new CacheLibraryInfo(mirrorFile.getName(), originalAttributes.lastModified, originalAttributes.length);
CacheLibraryInfo.ourCachedLibraryInfo.put(path, info);
return mirrorFile;
} catch (IOException ex) {
CacheLibraryInfo.ourCachedLibraryInfo.markCorrupted();
reportIOErrorWithJars(originalFile, mirrorFile != null ? mirrorFile : new File(jarDir, originalFile.getName()), ex);
return originalFile;
}
}
Aggregations