mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
update VirtualFile length in the right time
This commit is contained in:
@@ -6,9 +6,11 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.newvfs.ManagingFS;
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -22,13 +24,15 @@ public class LocalFileSystemTest extends IdeaTestCase{
|
||||
|
||||
public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
stream.write(bom);
|
||||
if (bom != null) {
|
||||
stream.write(bom);
|
||||
}
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, charset);
|
||||
writer.write(content);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException {
|
||||
public static VirtualFile createTempFile(@NonNls String ext, @Nullable byte[] bom, @NonNls String content, Charset charset) throws IOException {
|
||||
File temp = FileUtil.createTempFile("copy", "." + ext);
|
||||
setContentOnDisk(temp, bom, content, charset);
|
||||
|
||||
@@ -257,4 +261,21 @@ public class LocalFileSystemTest extends IdeaTestCase{
|
||||
VirtualFile root = LocalFileSystem.getInstance().findFileByPath("");
|
||||
assertNotNull(root);
|
||||
}
|
||||
|
||||
public void testFileLength() throws Exception {
|
||||
|
||||
File file = FileUtil.createTempFile("test", "txt");
|
||||
FileUtil.writeToFile(file, "hello");
|
||||
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
|
||||
assertNotNull(virtualFile);
|
||||
String s = VfsUtil.loadText(virtualFile);
|
||||
assertEquals("hello", s);
|
||||
assertEquals(5, virtualFile.getLength());
|
||||
|
||||
FileUtil.writeToFile(file, "new content");
|
||||
((PersistentFS)ManagingFS.getInstance()).cleanPersistedContents();
|
||||
s = VfsUtil.loadText(virtualFile);
|
||||
assertEquals("new content", s);
|
||||
assertEquals(11, virtualFile.getLength());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -460,6 +460,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent {
|
||||
|
||||
if (reloadFromDelegate) {
|
||||
final NewVirtualFileSystem delegate = getDelegate(file);
|
||||
FSRecords.setLength(getFileId(file), delegate.getLength(file));
|
||||
final byte[] content = delegate.contentsToByteArray(file);
|
||||
|
||||
ApplicationEx application = (ApplicationEx)ApplicationManager.getApplication();
|
||||
@@ -469,8 +470,6 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent {
|
||||
content.length <= FILE_LENGTH_TO_CACHE_THRESHOLD) {
|
||||
synchronized (INPUT_LOCK) {
|
||||
writeContent(file, new ByteSequence(content), delegate.isReadOnly());
|
||||
|
||||
FSRecords.setLength(getFileId(file), content.length);
|
||||
setFlag(file, MUST_RELOAD_CONTENT, false);
|
||||
}
|
||||
}
|
||||
@@ -498,6 +497,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent {
|
||||
if (mustReloadContent(file) || (contentStream = readContent(file)) == null) {
|
||||
final NewVirtualFileSystem delegate = getDelegate(file);
|
||||
final long len = delegate.getLength(file);
|
||||
FSRecords.setLength(getFileId(file), len);
|
||||
final InputStream nativeStream = delegate.getInputStream(file);
|
||||
|
||||
if (len > FILE_LENGTH_TO_CACHE_THRESHOLD) return nativeStream;
|
||||
@@ -519,7 +519,6 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent {
|
||||
synchronized (INPUT_LOCK) {
|
||||
if (getBytesRead() == len) {
|
||||
writeContent(file, new ByteSequence(cache.getInternalBuffer(), 0, cache.size()), readOnly);
|
||||
FSRecords.setLength(getFileId(file), len);
|
||||
setFlag(file, MUST_RELOAD_CONTENT, false);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -142,6 +142,10 @@ public class PathManagerEx {
|
||||
return getTestDataPath(strategy);
|
||||
}
|
||||
|
||||
public static String getTestDataPath(String path) throws IllegalStateException {
|
||||
return getTestDataPath() + path.replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand for calling {@link #getTestDataPath(TestDataLookupStrategy)} with strategy obtained via call to
|
||||
* {@link #determineLookupStrategy(Class)} with the given class.
|
||||
|
||||
Reference in New Issue
Block a user