Creates a directory in the Alluxio filesystem space. It will not throw any exception if the
destination directory already exists.

@param dstPath the {@link AlluxioURI} of the destination directory which will be created
332778
private void createDstDir(AlluxioURI dstPath) throws AlluxioException, IOException {
    try {
      mFileSystem.createDirectory(dstPath);
    } catch (FileAlreadyExistsException e) {
      // it's fine if the directory already exists
    }

    URIStatus dstStatus = mFileSystem.getStatus(dstPath);
    if (!dstStatus.isFolder()) {
      throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
  }
738979
@Override
  public void setWorkingDirectory(Path hadoopPath) {
    long startTime = System.nanoTime();
    Preconditions.checkArgument(hadoopPath != null, "hadoopPath must not be null");

    logger.atFine().log("GHFS.setWorkingDirectory: %s", hadoopPath);
    URI gcsPath = FileInfo.convertToDirectoryPath(pathCodec, getGcsPath(hadoopPath));
    Path newPath = getHadoopPath(gcsPath);

    // Ideally we should check (as we did earlier) if the given path really points to an existing
    // directory. However, it takes considerable amount of time for that check which hurts perf.
    // Given that HDFS code does not do such checks either, we choose to not do them in favor of
    // better performance.

    workingDirectory = newPath;
    logger.atFine().log("GHFS.setWorkingDirectory: => %s", workingDirectory);

    long duration = System.nanoTime() - startTime;
    increment(Counter.SET_WD);
    increment(Counter.SET_WD_TIME, duration);
  }
1151941
public static void prepareFilePath(AlluxioURI alluxioPath, String ufsPath, FileSystem fs,
      UnderFileSystem ufs) throws AlluxioException, IOException {
    AlluxioURI dstPath = new AlluxioURI(ufsPath);
    String parentPath = dstPath.getParent().getPath();
    // creates the parent folder if it does not exist
    if (!ufs.isDirectory(parentPath)) {
      // Create ancestor directories from top to the bottom. We cannot use recursive create parents
      // here because the permission for the ancestors can be different.
      Stack<Pair<String, MkdirsOptions>> ufsDirsToMakeWithOptions = new Stack<>();
      AlluxioURI curAlluxioPath = alluxioPath.getParent();
      AlluxioURI curUfsPath = dstPath.getParent();
      // Stop at Alluxio mount point because the mapped directory in UFS may not exist.
      while (curUfsPath != null && !ufs.isDirectory(curUfsPath.toString())
          && curAlluxioPath != null) {
        URIStatus curDirStatus = fs.getStatus(curAlluxioPath);
        if (curDirStatus.isMountPoint()) {
          throw new IOException(ExceptionMessage.UFS_PATH_DOES_NOT_EXIST.getMessage(curUfsPath));
        }
        ufsDirsToMakeWithOptions.push(new Pair<>(curUfsPath.toString(),
            MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false)
                .setOwner(curDirStatus.getOwner())
                .setGroup(curDirStatus.getGroup())
                .setMode(new Mode((short) curDirStatus.getMode()))));
        curAlluxioPath = curAlluxioPath.getParent();
        curUfsPath = curUfsPath.getParent();
      }
      while (!ufsDirsToMakeWithOptions.empty()) {
        Pair<String, MkdirsOptions> ufsDirAndPerm = ufsDirsToMakeWithOptions.pop();
        // UFS mkdirs might fail if the directory is already created. If so, skip the mkdirs
        // and assume the directory is already prepared, regardless of permission matching.
        if (!ufs.mkdirs(ufsDirAndPerm.getFirst(), ufsDirAndPerm.getSecond())
            && !ufs.isDirectory(ufsDirAndPerm.getFirst())) {
          throw new IOException("Failed to create dir: " + ufsDirAndPerm.getFirst());
        }
      }
    }
  }
801801
public static void uncompressEveryFileFromDirectory(File srcPath, File dstPath) throws IOException
   {
      if (srcPath.isDirectory())
      {
         if (!dstPath.exists())
         {
            dstPath.mkdirs();
         }

         String files[] = srcPath.list();
         for (int i = 0; i < files.length; i++)
         {
            uncompressEveryFileFromDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
         }
      }
      else
      {
         ZipInputStream in = null;
         OutputStream out = null;

         try
         {
            in = new ZipInputStream(new FileInputStream(srcPath));
            in.getNextEntry();

            out = new FileOutputStream(dstPath);

            transfer(in, out);
         }
         finally
         {
            if (in != null)
            {
               in.close();
            }

            if (out != null)
            {
               out.close();
            }
         }
      }
   }
491633
@Override
    public T addAsDirectory(String path) throws IllegalArgumentException {
        this.getArchive().addAsDirectory(path);
        return covarientReturn();
    }
625098
@Override
    public T addAsDirectory(final ArchivePath path) throws IllegalArgumentException {
        // Precondition check
        Validate.notNull(path, "path must be specified");

        // Adjust the path to remove any trailing slash
        ArchivePath adjustedPath = new BasicPath(PathUtil.optionallyRemoveFollowingSlash(path.get()));
        return addAsset(adjustedPath, null);
    }
720485
private static void createDirectory(Path path) throws IOException {
		try {
			Files.createDirectory(path);
		} catch (FileAlreadyExistsException e) {
			if (!Files.isDirectory(path)) {
				throw e;
			}
		}
	}
1176112
final AbstractSingleFileObjectStore.Directory makeDirectory(int minimumNodeSize,
                                                                long directoryRootByteAddress,
                                                                long directoryRootLength)
                    throws ObjectManagerException {
        return new Directory(minimumNodeSize,
                             directoryRootByteAddress,
                             directoryRootLength);
    }
45582
private String createDirectoryPath(String path)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "createDirectoryPath", "Path="+path);

        StringBuilder directoryPath = new StringBuilder("");

        if ((path != null) && (path.length() > 0))
        {
            // Defect 287722
            // Are we on unix? If so then we need
            // to make sure we replace the first
            // slash if present as it will be
            // removed by the tokenizer.
            if (path.charAt(0) == '/')
            {
                directoryPath.append("/");
            }

            // Are we UNC format? If so then we need
            // to make sure we replace the first
            // two backslashes as they will be
            // removed by the tokenizer.
            if (path.charAt(0) == '\\' && path.charAt(1) == '\\')
            {
                directoryPath.append("\\\\");
            }

            final StringTokenizer tokenizer = new StringTokenizer(path, "\\/");

            while (tokenizer.hasMoreTokens())
            {
                final String pathChunk = tokenizer.nextToken();

                directoryPath.append(pathChunk);

                // Check to see if the directory exists.
                File test = new File(directoryPath.toString());
                if (!test.exists())
                {
                    // Create the directory.
                    test.mkdir();
                }

                if (tokenizer.hasMoreTokens())
                {
                    directoryPath.append(File.separator);
                }
            }
        }

        String retval = directoryPath.toString();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "createDirectoryPath", retval);
        return retval;
    }
791424
public Sftp put(String srcFilePath, String destPath) {
		return put(srcFilePath, destPath, Mode.OVERWRITE);
	}
172084
public static void move(String srcPath, String dstPath) throws IOException {
    Files.move(Paths.get(srcPath), Paths.get(dstPath), StandardCopyOption.REPLACE_EXISTING);
  }
458818
public static void mkdirsIfNotExists(Location location) throws IOException {
    // Need to check && mkdir && check to deal with race condition
    if (!location.isDirectory() && !location.mkdirs() && !location.isDirectory()) {
      throw new IOException("Failed to create directory at " + location.toURI());
    }
  }
1260300
public static void makesureDirExists(Path dirPath) throws IOException {
		Validate.notNull(dirPath);
		Files.createDirectories(dirPath);
	}
289524
public void copyToLocalFile(boolean delSrc, Path src, Path dst)
    throws IOException {
    fs.copyToLocalFile(delSrc, src, dst);
  }
610492
private void createPropertiesFolder() throws IOException {
        if(!Files.exists(propertiesLocation.toPath()))
            Files.createDirectories(propertiesLocation.toPath());
    }
939795
private void createResourceFolder() throws IOException {
        if(!Files.exists(resourceLocation.toPath()))
            Files.createDirectories(resourceLocation.toPath());
    }
1064421
@Override
    public DirectoryStream<Path> newDirectoryStream(final Path dir, final Filter<? super Path> filter)
        throws IOException {
        final FileSystem fs = dir.getFileSystem();
        if (!(fs instanceof ShrinkWrapFileSystem)) {
            throw new IllegalArgumentException("Expected ShrinkWrap File System for Path: " + dir.toString());
        }
        return new ShrinkWrapDirectoryStream(dir, (ShrinkWrapFileSystem) fs, filter);
    }