/** * Parses the TRASH file name to extract the original path. * * @param name The TRASH short (entry) name. * @return The original path, or null in case of failure. */ public static IgfsPath extractOriginalPathFromTrash(String name) { int idx = name.indexOf(TRASH_NAME_SEPARATOR); assert idx >= 0; String path = name.substring(idx + 1, name.length()); return new IgfsPath(path); }
/** * Convert IGFS path into Hadoop path. * * @param path IGFS path. * @return Hadoop path. */ private Path convert(IgfsPath path) { return new Path(IGFS_SCHEME, uriAuthority, path.toString()); }
@Override public Boolean onSuccess(Map<IgfsPath, IgfsEntryInfo> infos) throws Exception { IgfsEntryInfo srcInfo = infos.get(src); IgfsEntryInfo srcParentInfo = infos.get(src.parent()); IgfsEntryInfo destInfo = infos.get(dest); IgfsEntryInfo destParentInfo = dest.parent() != null ? infos.get(dest.parent()) : null; moveNonTx(srcInfo.id(), src.name(), srcParentInfo.id(), dest.name(), destParentInfo.id()); else { "because destination path already exists and it is a file: " + dest); else moveNonTx(srcInfo.id(), src.name(), srcParentInfo.id(), src.name(), destInfo.id()); pendingEvts.add(new IgfsEvent( src, destInfo == null ? dest : new IgfsPath(dest, src.name()), locNode, EventType.EVT_IGFS_FILE_RENAMED));
/** * Read non-null path from the input. * * @param in Input. * @return IGFS path. * @throws IOException If failed. */ public static IgfsPath readPath(ObjectInput in) throws IOException { IgfsPath res = new IgfsPath(); res.readExternal(in); return res; }
@Override public Boolean onSuccess(Map<IgfsPath, IgfsEntryInfo> infos) throws Exception { fs.mkdirs(path, props); assert !infos.isEmpty(); // Now perform synchronization again starting with the last created parent. IgfsPath parentPath = null; for (IgfsPath curPath : infos.keySet()) { if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; } assert parentPath != null; IgfsEntryInfo parentPathInfo = infos.get(parentPath); synchronize(fs, parentPath, parentPathInfo, path, true, null); if (evts.isRecordable(EventType.EVT_IGFS_DIR_CREATED)) { IgfsPath evtPath = path; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new IgfsEvent(evtPath, locNode, EventType.EVT_IGFS_DIR_CREATED)); evtPath = evtPath.parent(); assert evtPath != null; // If this fails, then ROOT does not exist. } } return true; }
/** * Test public methods of igfs path. * * @throws Exception In case of any exception. */ @Test public void testMethods() throws Exception { IgfsPath path = new IgfsPath("/a/s/d/f"); validateParent("/a/s/d/f", "/a/s/d"); validateParent("/a/s/d", "/a/s"); validateParent("/a/s", "/a"); validateParent("/a", "/"); validateParent("/", null); assertEquals(new IgfsPath("/a/s/d/f-2"), path.suffix("-2")); assertEquals(Arrays.asList("a", "s", "d", "f"), path.components()); assertEquals(4, path.depth()); assertEquals(3, path.parent().depth()); assertEquals("f", path.name()); assertEquals(path, mu(path)); IgfsPath parent = path.parent(); assertTrue(path.compareTo(new IgfsPath(parent, "e")) > 0); assertTrue(path.compareTo(new IgfsPath(parent, "g")) < 0); }
List<String> components = endPath.components(); for (int i = startPath.components().size(); i < components.size(); i++) { curPath = new IgfsPath(curPath, components.get(i)); if (!status.isDirectory() && !curPath.equals(endPath)) throw new IgniteCheckedException("Failed to create path the locally because secondary file " + "system directory structure was modified concurrently and the path is not a directory as " + created.put(curPath.parent(), parentInfo);
if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; IgfsPath parent0 = path.parent(); if (!parentPath.equals(parent0)) { parentInfo = synchronize(fs, parentPath, parentInfo, parent0, true, null); IgfsPath evtPath = parent0; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new IgfsEvent(evtPath, locNode, EventType.EVT_IGFS_DIR_CREATED)); evtPath = evtPath.parent(); IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), path.name(), newInfo); path.name(), parentInfo.listing().get(path.name()).fileId())); createNewEntry(newInfo, parentInfo.id(), path.name()); // Put new one.
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (o == this) return true; if (o == null || !(o instanceof LocalFileSystemBlockKey)) return false; LocalFileSystemBlockKey that = (LocalFileSystemBlockKey)o; return blockId == that.blockId && path.equals(that.path); }
IgfsPath parentPath = path.parent(); IgniteUuid parentId = ids.get(ids.size() - 2); break; else { parentPath = parentPath.parent(); parentId = ids.get(j); IgfsPath parentPath = path.parent(); if (parentPath.equals(firstParentPath)) infos.put(firstParentPath, idToInfo.get(pathToId.get(firstParentPath))); else {
/** * Get parent entity. * * @return Parent entity. */ public IgfsPathIds parent() { assert ids.length > 1; String[] parentParts = new String[parts.length - 1]; IgniteUuid[] parentIds = new IgniteUuid[ids.length - 1]; System.arraycopy(parts, 0, parentParts, 0, parentParts.length); System.arraycopy(ids, 0, parentIds, 0, parentIds.length); return new IgfsPathIds(path.parent(), parentParts, parentIds); }
if (mode.getKey().isSubDirectoryOf(resMode.getKey())) { assert resMode.getValue() != null; dualParentsContainingPrimaryChildren.add(mode.getKey().parent());
/** {@inheritDoc} */ @Override public int compareTo(@NotNull LocalFileSystemBlockKey o) { int res = path.compareTo(o.path); if (res != 0) return res; long v1 = blockId; long v2 = o.blockId; if (v1 != v2) return v1 > v2 ? 1 : -1; return 0; }
/** * Gets all file IDs for components of specified path possibly skipping existing transaction. Result cannot * be empty - there is at least root element. But each element (except the first) can be {@code null} if such * files don't exist. * * @param path Path. * @param skipTx Whether to skip existing transaction. * @return Collection of file IDs for components of specified path. * @throws IgniteCheckedException If failed. */ private List<IgniteUuid> fileIds(IgfsPath path, boolean skipTx) throws IgniteCheckedException { assert path != null; // Path components. Collection<String> components = path.components(); // Collection of file IDs for components of specified path. List<IgniteUuid> ids = new ArrayList<>(components.size() + 1); ids.add(IgfsUtils.ROOT_ID); // Always add root ID. IgniteUuid fileId = IgfsUtils.ROOT_ID; for (String s : components) { assert !s.isEmpty(); if (fileId != null) fileId = fileId(fileId, s, skipTx); ids.add(fileId); } return ids; }
/** * Test directory move when source parent is the root. * * @throws Exception If failed. */ @Test public void testMoveDirectorySourceParentRoot() throws Exception { IgfsPath dir = new IgfsPath("/" + SUBSUBDIR.name()); create(igfs, paths(DIR_NEW, SUBDIR_NEW, dir), null); igfs.rename(dir, SUBDIR_NEW); checkExist(igfs, igfsSecondary, new IgfsPath(SUBDIR_NEW, SUBSUBDIR.name())); checkNotExist(igfs, igfsSecondary, dir); }
@Override public Object call() throws Exception { int id = cnt.incrementAndGet(); IgfsPath f = new IgfsPath(path.parent(), "asdf" + (id > 1 ? "-" + id : "")); try (IgfsOutputStream out = fs.create(f, 0, true, null, 0, 1024, null)) { assertNotNull(out); cleanUp.add(f); // Add all created into cleanup list. U.copy(new IgfsTestInputStream(size, salt), out); } return null; } }, WRITING_THREADS_CNT, "perform-multi-thread-writing");