public void testFindRoot() throws IOException {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath("wrong_path");
    assertNull(root);

    VirtualFile root2;
    if (SystemInfo.isWindows) {
      root = LocalFileSystem.getInstance().findFileByPath("\\\\unit-133");
      assertNotNull(root);
      root2 = LocalFileSystem.getInstance().findFileByPath("//UNIT-133");
      assertNotNull(root2);
      assertEquals(String.valueOf(root2), root, root2);
      RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));

      root = LocalFileSystem.getInstance().findFileByIoFile(new File("\\\\unit-133"));
      assertNotNull(root);
      RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));

      if (new File("c:").exists()) {
        root = LocalFileSystem.getInstance().findFileByPath("c:");
        assertNotNull(root);
        assertEquals("C:/", root.getPath());

        root2 = LocalFileSystem.getInstance().findFileByPath("C:\\");
        assertEquals(String.valueOf(root2), root, root2);
      }
    } else if (SystemInfo.isUnix) {
      root = LocalFileSystem.getInstance().findFileByPath("/");
      assertNotNull(root);
      assertEquals(root.getPath(), "/");
    }

    root = LocalFileSystem.getInstance().findFileByPath("");
    assertNotNull(root);

    File jarFile = IoTestUtil.createTestJar();
    root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/");
    assertNotNull(root);

    root2 =
        VirtualFileManager.getInstance()
            .findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/");
    assertEquals(String.valueOf(root2), root, root2);

    if (!SystemInfo.isFileSystemCaseSensitive) {
      root2 =
          VirtualFileManager.getInstance()
              .findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/");
      assertEquals(String.valueOf(root2), root, root2);
    }
  }
  @Nullable
  private VirtualFileSystemEntry findChild(
      @NotNull String name,
      boolean doRefresh,
      boolean ensureCanonicalName,
      @NotNull NewVirtualFileSystem delegate) {
    boolean ignoreCase = !delegate.isCaseSensitive();
    Comparator comparator = getComparator(ignoreCase);
    VirtualFileSystemEntry result = doFindChild(name, ensureCanonicalName, delegate, comparator);

    if (result == NULL_VIRTUAL_FILE) {
      result = doRefresh ? createAndFindChildWithEventFire(name, delegate) : null;
    } else if (result != null
        && doRefresh
        && delegate.isDirectory(result) != result.isDirectory()) {
      RefreshQueue.getInstance().refresh(false, false, null, result);
      result = findChild(name, false, ensureCanonicalName, delegate);
    }

    if (result == null) {
      addToAdoptedChildren(!delegate.isCaseSensitive(), name, comparator);
    }

    return result;
  }
 private void unzip(String path, boolean moduleMode) {
   try {
     File dir = new File(path);
     ZipInputStream zipInputStream = myTemplate.getStream();
     ZipUtil.unzip(
         ProgressManager.getInstance().getProgressIndicator(),
         dir,
         zipInputStream,
         moduleMode ? PATH_CONVERTOR : null);
     String iml =
         ContainerUtil.find(
             dir.list(),
             new Condition<String>() {
               @Override
               public boolean value(String s) {
                 return s.endsWith(".iml");
               }
             });
     if (moduleMode) {
       File from = new File(path, iml);
       File to = new File(getModuleFilePath());
       if (!from.renameTo(to)) {
         throw new IOException("Can't rename " + from + " to " + to);
       }
     }
     VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
     if (virtualFile == null) {
       throw new IOException("Can't find " + dir);
     }
     RefreshQueue.getInstance().refresh(false, true, null, virtualFile);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
  private void refreshFiles(final Project project) {
    final List<VirtualFile> toRefreshFiles = new ArrayList<VirtualFile>();
    final List<VirtualFile> toRefreshDirs = new ArrayList<VirtualFile>();
    for (VirtualFile file : myFilesToRefresh) {
      if (file == null) continue;
      if (file.isDirectory()) {
        toRefreshDirs.add(file);
      } else {
        toRefreshFiles.add(file);
      }
    }
    // if refresh asynchronously, local changes would also be notified that they are dirty
    // asynchronously,
    // and commit could be executed while not all changes are visible
    filterOutInvalid(myFilesToRefresh);
    RefreshQueue.getInstance()
        .refresh(
            true,
            true,
            new Runnable() {
              public void run() {
                if (project.isDisposed()) return;
                filterOutInvalid(toRefreshFiles);
                filterOutInvalid(toRefreshDirs);

                final VcsDirtyScopeManager vcsDirtyScopeManager =
                    VcsDirtyScopeManager.getInstance(project);
                vcsDirtyScopeManager.filesDirty(toRefreshFiles, toRefreshDirs);
              }
            },
            myFilesToRefresh);
    myFilesToRefresh.clear();
  }
 @Nullable
 private VirtualFileSystemEntry createAndFindChildWithEventFire(
     @NotNull String name, @NotNull NewVirtualFileSystem delegate) {
   final VirtualFile fake = new FakeVirtualFile(this, name);
   final FileAttributes attributes = delegate.getAttributes(fake);
   if (attributes == null) return null;
   final String realName = delegate.getCanonicallyCasedName(fake);
   final VFileCreateEvent event =
       new VFileCreateEvent(null, this, realName, attributes.isDirectory(), true);
   RefreshQueue.getInstance().processSingleEvent(event);
   return findChild(realName);
 }
예제 #6
0
 private static void refreshFiles(
     final List<VirtualFile> filesToRefresh, final Runnable runnable) {
   RefreshQueue.getInstance().refresh(true, true, runnable, filesToRefresh);
 }