[vfs] more accurate file existence check allows moving broken symlinks (IDEA-143989)

This commit is contained in:
Roman Shevchenko
2015-08-17 20:24:38 +02:00
parent dbdd347eca
commit ce324254de
2 changed files with 24 additions and 1 deletions
@@ -516,7 +516,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem {
}
File ioFile = convertToIOFile(file);
if (!ioFile.exists()) {
if (FileSystemUtil.getAttributes(ioFile) == null) {
throw new FileNotFoundException(VfsBundle.message("file.not.exist.error", ioFile.getPath()));
}
File ioParent = convertToIOFile(newParent);
@@ -37,6 +37,7 @@ import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl;
import com.intellij.openapi.vfs.newvfs.persistent.RefreshWorker;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;
@@ -638,4 +639,26 @@ public class LocalFileSystemTest extends PlatformTestCase {
}
}.execute();
}
public void testBrokenSymlinkMove() throws IOException, InterruptedException {
final File srcDir = IoTestUtil.createTestDir("src");
final File link = IoTestUtil.createSymLink(srcDir.getPath() + "/missing", srcDir.getPath() + "/link", false);
final File dstDir = IoTestUtil.createTestDir("dst");
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
VirtualFile file = myFS.refreshAndFindFileByIoFile(link);
assertNotNull(file);
VirtualFile target = myFS.refreshAndFindFileByIoFile(dstDir);
assertNotNull(target);
myFS.moveFile(this, file, target);
}
}.execute();
assertOrderedEquals(ArrayUtil.EMPTY_STRING_ARRAY, srcDir.list());
assertOrderedEquals(new String[]{link.getName()}, dstDir.list());
}
}