/** * Constructor. * * @param path Path. * @param ids Resolved path IDs. * @param parentPath Parent path. * @param parentInfo Parent info. */ PathDescriptor(GridGgfsPath path, List<GridUuid> ids, GridGgfsPath parentPath, GridGgfsFileInfo parentInfo) { assert path != null; assert ids != null && !ids.isEmpty(); assert parentPath == null && parentInfo == null || parentPath != null && parentInfo != null; assert parentPath == null || parentPath != null && path.isSubDirectoryOf(parentPath); this.path = path; this.ids = ids; this.parentPath = parentPath; this.parentInfo = parentInfo; }
/** * Constructor. * * @param path Path. * @param ids Resolved path IDs. * @param parentPath Parent path. * @param parentInfo Parent info. */ PathDescriptor(GridGgfsPath path, List<GridUuid> ids, GridGgfsPath parentPath, GridGgfsFileInfo parentInfo) { assert path != null; assert ids != null && !ids.isEmpty(); assert parentPath == null && parentInfo == null || parentPath != null && parentInfo != null; assert parentPath == null || parentPath != null && path.isSubDirectoryOf(parentPath); this.path = path; this.ids = ids; this.parentPath = parentPath; this.parentInfo = parentInfo; }
/** * Update ID with the given index. * * @param newParentPath New parent path. * @param newParentInfo New parent info. */ private void updateParent(GridGgfsPath newParentPath, GridGgfsFileInfo newParentInfo) { assert newParentPath != null; assert newParentInfo != null; assert path.isSubDirectoryOf(newParentPath); parentPath = newParentPath; parentInfo = newParentInfo; ids.set(newParentPath.components().size(), newParentInfo.id()); }
/** * Update ID with the given index. * * @param newParentPath New parent path. * @param newParentInfo New parent info. */ private void updateParent(GridGgfsPath newParentPath, GridGgfsFileInfo newParentInfo) { assert newParentPath != null; assert newParentInfo != null; assert path.isSubDirectoryOf(newParentPath); parentPath = newParentPath; parentInfo = newParentInfo; ids.set(newParentPath.components().size(), newParentInfo.id()); }
@Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception { fs.mkdirs(path, props); assert !infos.isEmpty(); // Now perform synchronization again starting with the last created parent. GridGgfsPath parentPath = null; for (GridGgfsPath curPath : infos.keySet()) { if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; } assert parentPath != null; GridGgfsFileInfo parentPathInfo = infos.get(parentPath); synchronize(fs, parentPath, parentPathInfo, path, true, null); if (evts.isRecordable(EVT_GGFS_DIR_CREATED)) { GridGgfsPath evtPath = path; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new GridGgfsEvent(evtPath, locNode, EVT_GGFS_DIR_CREATED)); evtPath = evtPath.parent(); assert evtPath != null; // If this fails, then ROOT does not exist. } } return true; }
@Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception { fs.mkdirs(path, props); assert !infos.isEmpty(); // Now perform synchronization again starting with the last created parent. GridGgfsPath parentPath = null; for (GridGgfsPath curPath : infos.keySet()) { if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath; } assert parentPath != null; GridGgfsFileInfo parentPathInfo = infos.get(parentPath); synchronize(fs, parentPath, parentPathInfo, path, true, null); if (evts.isRecordable(EVT_GGFS_DIR_CREATED)) { GridGgfsPath evtPath = path; while (!parentPath.equals(evtPath)) { pendingEvts.addFirst(new GridGgfsEvent(evtPath, locNode, EVT_GGFS_DIR_CREATED)); evtPath = evtPath.parent(); assert evtPath != null; // If this fails, then ROOT does not exist. } } return true; }
/** * Await for any pending finished writes on the children paths. * * @param paths Paths to check. */ void await(GridGgfsPath... paths) { assert paths != null; for (Map.Entry<GridGgfsPath, GridGgfsFileWorker> workerEntry : workerMap.entrySet()) { GridGgfsPath workerPath = workerEntry.getKey(); boolean await = false; for (GridGgfsPath path : paths) { if (workerPath.isSubDirectoryOf(path) || workerPath.isSame(path)) { await = true; break; } } if (await) { GridGgfsFileWorkerBatch batch = workerEntry.getValue().currentBatch(); if (batch != null) { try { batch.awaitIfFinished(); } catch (GridException ignore) { // No-op. } } } } }
/** * Await for any pending finished writes on the children paths. * * @param paths Paths to check. */ void await(GridGgfsPath... paths) { assert paths != null; for (Map.Entry<GridGgfsPath, GridGgfsFileWorker> workerEntry : workerMap.entrySet()) { GridGgfsPath workerPath = workerEntry.getKey(); boolean await = false; for (GridGgfsPath path : paths) { if (workerPath.isSubDirectoryOf(path) || workerPath.isSame(path)) { await = true; break; } } if (await) { GridGgfsFileWorkerBatch batch = workerEntry.getValue().currentBatch(); if (batch != null) { try { batch.awaitIfFinished(); } catch (GridException ignore) { // No-op. } } } } }
if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath;
if (parentPath == null || curPath.isSubDirectoryOf(parentPath)) parentPath = curPath;
if (dest.isSubDirectoryOf(src)) throw new GridGgfsInvalidPathException("Failed to rename directory (cannot move directory of " + "upper level to self sub-dir) [src=" + src + ", dest=" + dest + ']');
if (dest.isSubDirectoryOf(src)) throw new GridGgfsInvalidPathException("Failed to rename directory (cannot move directory of " + "upper level to self sub-dir) [src=" + src + ", dest=" + dest + ']');