mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[review feedback]: 1. remove getCheapFileSystemModificationCount & javadoc for getModificationCount(VirtualFile) and getFilesystemModificationCount
2. in tests also specify changes in local fs mod count (ManagingFS.getModificationCount) 3. more compact code
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -41,15 +42,11 @@ public abstract class ManagingFS implements FileSystemInterface {
|
||||
@NotNull
|
||||
public abstract DataOutputStream writeAttribute(@NotNull VirtualFile file, @NotNull FileAttribute att);
|
||||
|
||||
public abstract int getModificationCount(@NotNull VirtualFile fileOrDirectory);
|
||||
|
||||
/**
|
||||
* @deprecated to be removed in IDEA 16
|
||||
* @see #getModificationCount()
|
||||
* @return a number that's incremented every time something changes for the file: name, size, flags, content.
|
||||
* This number is persisted between IDE sessions and so it'll always increase. This method invocation means disk access, so it's not terribly cheap.
|
||||
*/
|
||||
public int getCheapFileSystemModificationCount() {
|
||||
return getModificationCount();
|
||||
}
|
||||
public abstract int getModificationCount(@NotNull VirtualFile fileOrDirectory);
|
||||
|
||||
/**
|
||||
* @return a number that's incremented every time something changes in the VFS, i.e. file hierarchy, names, flags, attributes, contents.
|
||||
@@ -67,10 +64,10 @@ public abstract class ManagingFS implements FileSystemInterface {
|
||||
public abstract int getStructureModificationCount();
|
||||
|
||||
/**
|
||||
* @deprecated to be removed in IDEA 16
|
||||
* @return a number that's incremented every time something changes in the VFS, i.e. file hierarchy, names, flags, attributes, contents.
|
||||
* @return a number that's incremented every time modification count for some file is advanced, @see {@link #getModificationCount(VirtualFile)}.
|
||||
* This number is persisted between IDE sessions and so it'll always increase. This method invocation means disk access, so it's not terribly cheap.
|
||||
*/
|
||||
@TestOnly
|
||||
public abstract int getFilesystemModificationCount();
|
||||
|
||||
public abstract long getCreationTimestamp();
|
||||
|
||||
+21
-18
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs.local;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.IoTestUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -182,30 +181,32 @@ public class PersistentFsTest extends PlatformTestCase {
|
||||
public void testModCountIncreases() throws IOException {
|
||||
VirtualFile vFile = setupFile();
|
||||
ManagingFS managingFS = ManagingFS.getInstance();
|
||||
int inSessionModCount = managingFS.getModificationCount();
|
||||
int globalModCount = managingFS.getFilesystemModificationCount();
|
||||
final int parentModCount = managingFS.getModificationCount(vFile.getParent());
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>)() -> {
|
||||
vFile.setWritable(false);
|
||||
return null;
|
||||
});
|
||||
WriteAction.run(() -> vFile.setWritable(false));
|
||||
|
||||
assertEquals(globalModCount + 1, managingFS.getModificationCount(vFile));
|
||||
assertEquals(globalModCount + 1, managingFS.getFilesystemModificationCount());
|
||||
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
|
||||
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
|
||||
|
||||
FSRecords.force();
|
||||
assertTrue(!FSRecords.isDirty());
|
||||
assertFalse(FSRecords.isDirty());
|
||||
++globalModCount;
|
||||
++inSessionModCount;
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>)() -> {
|
||||
vFile.setWritable(true); // 1
|
||||
vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset())); // 1 + timestamp + length
|
||||
return null;
|
||||
final long timestamp = vFile.getTimeStamp();
|
||||
WriteAction.run(() -> {
|
||||
vFile.setWritable(true); // 1 change
|
||||
vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset())); // content change + length change + maybe timestamp change
|
||||
});
|
||||
|
||||
assertEquals(globalModCount + 4, managingFS.getModificationCount(vFile));
|
||||
assertEquals(globalModCount + 4, managingFS.getFilesystemModificationCount());
|
||||
final int changesCount = timestamp == vFile.getTimeStamp() ? 3 : 4;
|
||||
assertEquals(globalModCount + changesCount, managingFS.getModificationCount(vFile));
|
||||
assertEquals(globalModCount + changesCount, managingFS.getFilesystemModificationCount());
|
||||
assertEquals(inSessionModCount + changesCount, managingFS.getModificationCount());
|
||||
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
|
||||
}
|
||||
|
||||
@@ -222,25 +223,26 @@ public class PersistentFsTest extends PlatformTestCase {
|
||||
ManagingFS managingFS = ManagingFS.getInstance();
|
||||
final int globalModCount = managingFS.getFilesystemModificationCount();
|
||||
final int parentModCount = managingFS.getModificationCount(vFile.getParent());
|
||||
int inSessionModCount = managingFS.getModificationCount();
|
||||
|
||||
FSRecords.force();
|
||||
assertTrue(!FSRecords.isDirty());
|
||||
assertFalse(FSRecords.isDirty());
|
||||
|
||||
FileAttribute attribute = new FileAttribute("test.attribute", 1, true);
|
||||
ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>)() -> {
|
||||
WriteAction.run(() -> {
|
||||
try(DataOutputStream output = attribute.writeAttribute(vFile)) {
|
||||
DataInputOutputUtil.writeINT(output, 1);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
assertEquals(globalModCount, managingFS.getModificationCount(vFile));
|
||||
assertEquals(globalModCount, managingFS.getFilesystemModificationCount());
|
||||
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
|
||||
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
|
||||
|
||||
assertTrue(FSRecords.isDirty());
|
||||
FSRecords.force();
|
||||
assertTrue(!FSRecords.isDirty());
|
||||
assertFalse(FSRecords.isDirty());
|
||||
|
||||
//
|
||||
int fileId = ((VirtualFileWithId)vFile).getId();
|
||||
@@ -250,6 +252,7 @@ public class PersistentFsTest extends PlatformTestCase {
|
||||
assertEquals(globalModCount, managingFS.getModificationCount(vFile));
|
||||
assertEquals(globalModCount, managingFS.getFilesystemModificationCount());
|
||||
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
|
||||
assertTrue(!FSRecords.isDirty());
|
||||
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
|
||||
assertFalse(FSRecords.isDirty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user