Esempio n. 1
0
  @Override
  public int getId(
      @NotNull VirtualFile parent, @NotNull String childName, @NotNull NewVirtualFileSystem fs) {
    int parentId = getFileId(parent);
    int[] children = FSRecords.list(parentId);

    if (children.length > 0) {
      // fast path, check that some child has same nameId as given name, this avoid O(N) on
      // retrieving names for processing non-cached children
      int nameId = FSRecords.getNameId(childName);
      for (final int childId : children) {
        if (nameId == FSRecords.getNameId(childId)) {
          return childId;
        }
      }
      // for case sensitive system the above check is exhaustive in consistent state of vfs
    }

    for (final int childId : children) {
      if (namesEqual(fs, childName, FSRecords.getName(childId))) return childId;
    }

    final VirtualFile fake = new FakeVirtualFile(parent, childName);
    final FileAttributes attributes = fs.getAttributes(fake);
    if (attributes != null) {
      final int child = createAndFillRecord(fs, fake, parentId, attributes);
      FSRecords.updateList(parentId, ArrayUtil.append(children, child));
      return child;
    }

    return 0;
  }
Esempio n. 2
0
 @NotNull
 private static String[] listPersisted(@NotNull int[] childrenIds) {
   String[] names = ArrayUtil.newStringArray(childrenIds.length);
   for (int i = 0; i < childrenIds.length; i++) {
     names[i] = FSRecords.getName(childrenIds[i]);
   }
   return names;
 }
Esempio n. 3
0
  private static void removeIdFromParentList(
      final int parentId, final int id, @NotNull VirtualFile parent, VirtualFile file) {
    int[] childList = FSRecords.list(parentId);

    int index = ArrayUtil.indexOf(childList, id);
    if (index == -1) {
      throw new RuntimeException(
          "Cannot find child ("
              + id
              + ")"
              + file
              + "\n\tin ("
              + parentId
              + ")"
              + parent
              + "\n\tactual children:"
              + Arrays.toString(childList));
    }
    childList = ArrayUtil.remove(childList, index);
    FSRecords.updateList(parentId, childList);
  }
Esempio n. 4
0
 private static void appendIdToParentList(final int parentId, final int childId) {
   int[] childrenList = FSRecords.list(parentId);
   childrenList = ArrayUtil.append(childrenList, childId);
   FSRecords.updateList(parentId, childrenList);
 }