<commit_before>
# `hdfs_mkdir(options, callback)`

Create an HDFS directory.

Options include:

*   `target`   
*   `krb5_user`   
*   `mode`   
*   `user`   
*   `group`   
*   `parent`   
*   `parent.mode`   
*   `parent.user`   
*   `parent.group`   

## Source Code

    module.exports = (options, callback) ->
      throw callback Error "Required option: 'target'" unless options.target
      options.mode ?= ''
      options.mode = mode.stringify options.mode
      options.user ?= ''
      options.group ?= ''
      options.parent ?= {}
      options.parent.mode ?= options.mode
      options.parent.mode = mode.stringify options.parent.mode if options.parent.mode
      options.parent.user ?= options.user
      options.parent.group ?= options.group
      wrap = (cmd) ->
        return cmd unless options.krb5_user
        "echo '#{options.krb5_user.password}' | kinit #{options.krb5_user.principal} >/dev/null && {\n#{cmd}\n}"
      @system.execute
        cmd: wrap """
        target="#{options.target}"
        if hdfs dfs -test -d $target; then
          # TODO: compare permissions and ownership
          exit 3;
        fi
        function create_dir {
          dir=$1
          mode=$2
          user=$3
          group=$4
          echo "Create dir $dir"
          # Use -p to prevent race conditions
          hdfs dfs -mkdir -p $dir
          if [ -n "$mode" ]; then
            echo "Change permissions to $mode"
            hdfs dfs -chmod $mode $dir
          fi
          if [ -n "$user" ]; then
            echo "Change owner ownership to $user"
            hdfs dfs -chown $user $dir
          fi
          if [ -n "$group" ]; then
            echo "Change group ownership to $group"
            hdfs dfs -chgrp $group $dir
          fi
        }
        function create_parent_dir {
          local dir=`dirname $1`
          if [ $dir == "/" ]; then return; fi
          if hdfs dfs -test -d $dir; then return; fi
          create_parent_dir $dir
          # echo "Create parent directory: $dir"
          create_dir \
            "$dir" \
            "#{options.parent.mode or ''}" \
            "#{options.parent.user or ''}" \
            "#{options.parent.group or ''}"
        }
        create_parent_dir $target
        create_dir \
          $target \
          "#{options.mode or ''}" \
          "#{options.user or ''}" \
          "#{options.group or ''}"
        """
        code_skipped: 3
        trap: true
      .then callback

## Dependecies

    {mode} = require 'nikita/src/misc'<commit_msg>lib/hdfs_mkdir: fix require<commit_after>
# `hdfs_mkdir(options, callback)`

Create an HDFS directory.

Options include:

*   `target`   
*   `krb5_user`   
*   `mode`   
*   `user`   
*   `group`   
*   `parent`   
*   `parent.mode`   
*   `parent.user`   
*   `parent.group`   

## Source Code

    module.exports = (options, callback) ->
      throw callback Error "Required option: 'target'" unless options.target
      options.mode ?= ''
      options.mode = mode.stringify options.mode
      options.user ?= ''
      options.group ?= ''
      options.parent ?= {}
      options.parent.mode ?= options.mode
      options.parent.mode = mode.stringify options.parent.mode if options.parent.mode
      options.parent.user ?= options.user
      options.parent.group ?= options.group
      wrap = (cmd) ->
        return cmd unless options.krb5_user
        "echo '#{options.krb5_user.password}' | kinit #{options.krb5_user.principal} >/dev/null && {\n#{cmd}\n}"
      @system.execute
        cmd: wrap """
        target="#{options.target}"
        if hdfs dfs -test -d $target; then
          # TODO: compare permissions and ownership
          exit 3;
        fi
        function create_dir {
          dir=$1
          mode=$2
          user=$3
          group=$4
          echo "Create dir $dir"
          # Use -p to prevent race conditions
          hdfs dfs -mkdir -p $dir
          if [ -n "$mode" ]; then
            echo "Change permissions to $mode"
            hdfs dfs -chmod $mode $dir
          fi
          if [ -n "$user" ]; then
            echo "Change owner ownership to $user"
            hdfs dfs -chown $user $dir
          fi
          if [ -n "$group" ]; then
            echo "Change group ownership to $group"
            hdfs dfs -chgrp $group $dir
          fi
        }
        function create_parent_dir {
          local dir=`dirname $1`
          if [ $dir == "/" ]; then return; fi
          if hdfs dfs -test -d $dir; then return; fi
          create_parent_dir $dir
          # echo "Create parent directory: $dir"
          create_dir \
            "$dir" \
            "#{options.parent.mode or ''}" \
            "#{options.parent.user or ''}" \
            "#{options.parent.group or ''}"
        }
        create_parent_dir $target
        create_dir \
          $target \
          "#{options.mode or ''}" \
          "#{options.user or ''}" \
          "#{options.group or ''}"
        """
        code_skipped: 3
        trap: true
      .then callback

## Dependecies

    {mode} = require 'nikita/lib/misc'
{'fraction_non_alphanumeric': 0.12568735271013354, 'fraction_numerical': 0.00432050274941084, 'mean_word_length': 1.6198559670781894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004626', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1536, 'n_words': 405}