assert that vfile rename/move/delete should happen in a write action

This commit is contained in:
peter
2016-11-21 09:57:47 +01:00
parent 398bfbcf4d
commit 443d443bb7
2 changed files with 11 additions and 0 deletions
@@ -208,6 +208,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
* @throws IOException if file failed to be renamed
*/
public void rename(Object requestor, @NotNull String newName) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (getName().equals(newName)) return;
if (!getFileSystem().isValidName(newName)) {
throw new IOException(VfsBundle.message("file.invalid.name.error", newName));
@@ -451,6 +452,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
* @throws IOException if file failed to be deleted
*/
public void delete(Object requestor) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
LOG.assertTrue(isValid(), "Deleting invalid file");
getFileSystem().deleteFile(requestor, this);
}
@@ -466,6 +468,8 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
* @throws IOException if file failed to be moved
*/
public void move(final Object requestor, @NotNull final VirtualFile newParent) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (getFileSystem() != newParent.getFileSystem()) {
throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl()));
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.vfs.newvfs.impl;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileTooBigException;
@@ -201,11 +202,13 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
@Override
public void delete(final Object requestor) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
ourPersistence.deleteFile(requestor, this);
}
@Override
public void rename(final Object requestor, @NotNull @NonNls final String newName) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (getName().equals(newName)) return;
validateName(newName);
ourPersistence.renameFile(requestor, this, newName);
@@ -258,6 +261,8 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
@Override
public void move(final Object requestor, @NotNull final VirtualFile newParent) throws IOException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
if (getFileSystem() != newParent.getFileSystem()) {
throw new IOException(VfsBundle.message("file.move.error", newParent.getPresentableUrl()));
}
@@ -323,6 +328,8 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile {
}
public void setParent(@NotNull VirtualFile newParent) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
VirtualDirectoryImpl parent = getParent();
parent.removeChild(this);