Recursively creates directories and files.
@param level current level of depth
@param parentPath the prefix to the path we have traversed into so far
@return -1 on error, 0 on success
492913
private static int CreateDFSPaths(int level, String parentPath) {
    Boolean isLeaf = false;
    Boolean isDir = false;
    if (level + 1 >= levels_) {
      isLeaf = true;
    }
    if (isLeaf) {
      if (type_.equals("dir")) {
        isDir = true;
      } else {
        isDir = false;
      }
    } else {
      isDir = true;
    }

    for (int i = 0; i < inodesPerLevel_; i++) {
      String path = parentPath + "/" + prefix_ + Integer.toString(i);
      //System.out.printf("Creating (isdir=%b) [%s]\n", isDir, path.toString());

      if (isDir) {
        try {
        	
          long startTime = System.nanoTime();
          if (dfsClient_.mkdirs(path) == false) {
            System.out.printf("Error in mkdirs(%s)\n", path);
            return -1;
          }
          timingMkdirs_.add(new Double((System.nanoTime() - startTime)/(1E9)));
          
          System.out.printf("Creating dir %s\n", path);

          totalCreateCount ++;
          if (totalCreateCount % COUNT_INCR == 0) {
            System.out.printf("Created paths so far: %d\n", totalCreateCount);
          }
          if (!isLeaf) {
            if (CreateDFSPaths(level+1, path) < 0) {
              System.out.printf("Error in CreateDFSPaths(%s)\n", path);
              return -1;
            }
          }
        } catch(IOException e) {
          e.printStackTrace();
          return -1;
        }	
      } else {
        try {
        	System.out.printf("Creating file %s\n", path);
        	
        	long startTime = System.nanoTime();
        	OutputStream os = dfsClient_.create(path, true);
          timingCreate_.add(new Double((System.nanoTime() - startTime)/(1E9)));
          
        	files_.put(path, os);

          totalCreateCount ++;
          if (totalCreateCount % COUNT_INCR == 0) {
            System.out.printf("Created paths so far: %d\n", totalCreateCount);
          }
        } catch( IOException e) {
          e.printStackTrace();
          return -1;
        }
      }
    }
    
    return 0;
  }
1197383
@Override
    public Path getParent() {
        final List<String> tokens = tokenize(this);
        // No parent?
        final int numTokens = tokens.size();
        if (numTokens == 0 || (numTokens == 1 && !this.isAbsolute())) {
            return null;
        }

        // Iterate over all but the last token and build a new path
        final StringBuffer sb = new StringBuffer();
        if (this.isAbsolute()) {
            sb.append(ArchivePath.SEPARATOR);
        }
        for (int i = 0; i < numTokens - 1; i++) {
            if (i >= 1) {
                sb.append(ArchivePath.SEPARATOR);
            }
            sb.append(tokens.get(i));
        }

        final String parentPath = sb.toString();
        return new ShrinkWrapPath(parentPath, fileSystem);
    }
1040992
def nextparent(self, parent, depth):
        '''
        
        '''
        if depth > 1:  # can't jump to parent of root node!
            pdir = os.path.dirname(self.name)
            line = 0
            for c, d in parent.traverse():
                if line > parent.curline and c.name.startswith(pdir):
                    parent.curline += 1
                line += 1
        else:  # otherwise just skip to next directory
            line = -1  # skip hidden parent node
            for c, d in parent.traverse():
                if line > parent.curline:
                    parent.curline += 1
                    if os.path.isdir(c.name) and c.name in parent.children[0:]:
                        break
                line += 1
628879
public static void deleteRecursive(Path start, boolean deleteStart) throws IOException {
		Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				Files.delete(file);
				return FileVisitResult.CONTINUE;
			}
			@Override
			public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
				if (e == null) {
					if (deleteStart || !Files.isSameFile(dir, start)) {
						Files.delete(dir);
					}
					return FileVisitResult.CONTINUE;
				} else {
					// directory iteration failed
					throw e;
				}
			}
		});
	}
147891
private void appendPath(final StringBuilder buf) {
        if (parentZipFileSlice != null) {
            parentZipFileSlice.appendPath(buf);
            if (buf.length() > 0) {
                buf.append("!/");
            }
        }
        buf.append(pathWithinParentZipFileSlice);
    }
1026186
function (context, path, callback) {
  path = normalize(path);
  var name = basename(path);
  var parentPath = dirname(path);

  var directoryNode;
  var directoryData;
  var parentDirectoryNode;
  var parentDirectoryData;

  function read_parent_directory_data(error, result) {
    if(error) {
      callback(error);
    } else {
      parentDirectoryNode = result;
      context.getObject(parentDirectoryNode.data, check_if_node_exists);
    }
  }

  function check_if_node_exists(error, result) {
    if(error) {
      callback(error);
    } else if(ROOT_DIRECTORY_NAME === name) {
      callback(new Errors.EBUSY(null, path));
    } else if(!result.hasOwnProperty(name)) {
      callback(new Errors.ENOENT(null, path));
    } else {
      parentDirectoryData = result;
      directoryNode = parentDirectoryData[name].id;
      context.getObject(directoryNode, check_if_node_is_directory);
    }
  }

  function check_if_node_is_directory(error, result) {
    if(error) {
      callback(error);
    } else if(result.type !== NODE_TYPE_DIRECTORY) {
      callback(new Errors.ENOTDIR(null, path));
    } else {
      directoryNode = result;
      context.getObject(directoryNode.data, check_if_directory_is_empty);
    }
  }

  function check_if_directory_is_empty(error, result) {
    if(error) {
      callback(error);
    } else {
      directoryData = result;
      if(Object.keys(directoryData).length > 0) {
        callback(new Errors.ENOTEMPTY(null, path));
      } else {
        _entry_from_parent_directory_node();
      }
    }
  }

  function update_time(error) {
    if(error) {
      callback(error);
    } else {
      var now = Date.now();
      update_node_times(context, parentPath, parentDirectoryNode, { mtime: now, ctime: now }, _node);
    }
  }

  function _entry_from_parent_directory_node() {
    delete parentDirectoryData[name];
    context.putObject(parentDirectoryNode.data, parentDirectoryData, update_time);
  }

  function _node(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.id, _data);
    }
  }

  function _data(error) {
    if(error) {
      callback(error);
    } else {
      context.delete(directoryNode.data, callback);
    }
  }

  find_node(context, parentPath, read_parent_directory_data);
}
672849
function(root, path) {
				if (path.indexOf(this.SEPARATOR) === 0) {
					root = this.rootNode;
					path = path.substring(1);
				} else {
					if (!root) {
						if (!this.currentDirectory) {
							/* no node to resolve the path in terms of */
							return null;
						}
						root = this.currentDirectory;
					}
				}
				var segments = path.substring(0, path.lastIndexOf(this.SEPARATOR)).split(this.SEPARATOR);
				var result = root;
				for (var i = 0; i < segments.length; i++) {
					if (segments[i].length > 0) {
						result = this.getChild(result, segments[i]);
						if (!result || !result.Directory) {
							/* non-existent directory */
							return null;
						}
					}
				}

				/*
				 * If the full path represents a directory then initiate the
				 * retrieval of its full node info and children.
				 */
				var lastSegment = path.substring(path.lastIndexOf(this.SEPARATOR) + 1);
				var child = this.getChild(result, lastSegment);
				if (child) {
					this._retrieveNode(child);
				}

				if (!result.Children) {
					this._retrieveNode(result);
				}
				return result;
			}
133554
def create_parent_folder(filename):
    
    path = os.path.dirname(filename)
    if path != '':
        make_folder(path)
127784
protected boolean checkParentDirs(String path, boolean createIfAbsent) throws IOException {
      String[] components = Util.components(path, SEPARATOR);
      if (components == null)
         return false;
      if (components.length == 1) // no parent directories to create, e.g. "data.txt"
         return true;

      StringBuilder sb = new StringBuilder();
      boolean first = true;

      for (int i = 0; i < components.length - 1; i++) {
         String tmp = components[i];
         if (!tmp.equals(SEPARATOR)) {
            if (first)
               first = false;
            else
               sb.append(SEPARATOR);
         }
         sb.append(tmp);
         String comp = sb.toString();
         if (comp.equals(SEPARATOR))
            continue;
         Metadata val = exists(comp);
         if (val != null) {
            if (val.isFile())
               throw new IOException(format("cannot create %s as component %s is a file", path, comp));
         } else if (createIfAbsent) {
            metadataCache.put(comp, new Metadata(0, System.currentTimeMillis(), chunkSize, Metadata.DIR));
         } else {
            // Couldn't find a component and we're not allowed to create components!
            return false;
         }

      }
      // check that we have found all the components we need.
      return true;
   }
11272
protected boolean deleteDirectory(Path path, boolean cleanParent) throws IOException {
        boolean pathExists = deleteIfExistsRecursively(path);
        if(pathExists && cleanParent) {
            cleanEmptyParentDirectory(path.getParent());
            return true;
        }
        return false;
    }
917641
function createParentPath(client, path, callback) {
  var parentDir = path.substring(0, path.lastIndexOf('/'));

  debug('createParentPath: "%s"', parentDir);

  if (parentDir.length != 0) {
    client.create(parentDir, function(err) {
      if (err) {
        if (err.code === NO_NODE) {
          return createParentPath(client, parentDir, function(err) {
            if (err) return callback(err);

            createParentPath(client, path, callback);
          });
        } else if (err.code !== NODE_EXISTS)
          return callback(err);
      }
      callback(null, path);
    });
  } else
    callback(null, path);
}
1040232
def prevparent(self, parent, depth):
        '''
        
        '''
        pdir = os.path.dirname(self.name)
        if depth > 1:  # can't jump to parent of root node!
            for c, d in parent.traverse():
                if c.name == self.name:
                    break
                if c.name.startswith(pdir):
                    parent.curline -= 1
        else:  # otherwise jus skip to previous directory
            pdir = self.name
            # - 1 otherwise hidden parent node throws count off & our
            # self.curline doesn't change!
            line = -1
            for c, d in parent.traverse():
                if c.name == self.name:
                    break
                if os.path.isdir(c.name) and c.name in parent.children[0:]:
                    parent.curline = line
                line += 1
        return pdir
265351
private boolean mkdir(boolean parent)
  {
    synchronized (_rootNode) {
      String fullPath = getFullPath();

      int head = 0;
      Node node = this._rootNode;

      while (node != null && head < fullPath.length()) {
        int tail = fullPath.indexOf('/', head);
        String name;

        if (tail == head) {
          head = tail + 1;
          continue;
        }
        if (tail == -1) {
          name = fullPath.substring(head);
          if (node.lookup(name) != null)
            return false;
          node.createDir(name);
          return true;
        }

        name = fullPath.substring(head, tail);
        Node next = node.lookup(name);

        if (next == null && parent)
          next = node.createDir(name);

        if (next == null || next.type != next.DIR)
          return false;

        node = next;
        head = tail + 1;
      }

      return false;
    }
  }
421275
public static String buildProperPath(String parentPath, String relativePathFromParent) {
        if (relativePathFromParent == null) return null;
        if (parentPath != null) {
            parentPath = parentPath.trim();
        }

        if (relativePathFromParent.startsWith(PATH_CURRENT)) {
            relativePathFromParent = relativePathFromParent.replaceFirst("(./)+", "");
        }

        String path;

        if (relativePathFromParent.startsWith(PATH_ROOT)) { //absolute
            path = relativePathFromParent;
        } else if (relativePathFromParent.startsWith(PATH_PARENT)) {
            while (relativePathFromParent.startsWith(PATH_PARENT)) {
                relativePathFromParent = relativePathFromParent.replaceFirst(PATH_PARENT, "");
                if (relativePathFromParent.startsWith(PATH_CURRENT)) {
                    relativePathFromParent = relativePathFromParent.replaceFirst(PATH_CURRENT, "");
                }
                parentPath = (parentPath == null || parentPath.equals(PATH_ROOT)) ? PATH_ROOT : getParentPath(parentPath);
            }
            path = parentPath + PATH_ROOT + relativePathFromParent;
        } else {
            path = parentPath + PATH_ROOT + relativePathFromParent;
        }

        return path.replaceAll("(/|\\./)+", "$1");
    }
394746
def make_parent_dirs(path, mode=0o777):
  
  parent = os.path.dirname(path)
  if parent:
    make_all_dirs(parent, mode)
  return path
4618
function create_node_in_parent(error, parentDirectoryNode) {
    if(error) {
      callback(error);
    } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY) {
      callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path));
    } else {
      parentNode = parentDirectoryNode;
      find_node(context, path, check_if_node_exists);
    }
  }
947550
public static @NonNull ModuleLayer createLayer(final @NonNull ModuleLayer parent, final @NonNull Set<Path> paths) {
    final ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()]));
    final Set<String> modules = finder.findAll().stream().map(reference -> reference.descriptor().name()).collect(Collectors.toSet());
    final Configuration configuration = parent.configuration().resolve(finder, ModuleFinder.of(), modules);
    final ClassLoader loader = ClassLoader.getSystemClassLoader();
    return parent.defineModulesWithOneLoader(configuration, loader);
  }