<commit_before>/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var nodyn      = require('nodyn'),
    util       = require('util'),
    blocking   = require('nodyn/blocking'),
    //posix      = Packages.jnr.posix.POSIXFactory.getPOSIX(new io.nodyn.posix.NodePosixHandler(), true),
    posix      = process._posix,
    Errno      = Packages.jnr.constants.platform.Errno,
    File       = Packages.java.io.File,
    Fs         = Packages.io.nodyn.fs.Fs,
    binding    = module.exports,
    statsCtor  = null;

// Executes work asynchronously if async is provided and is a function -
// otherwise, just executes the work and returns the result. If executing
// async and successful, the callback function is executed on the next tick.
// If there is an error and the throws param is falsy just returns the
// result.err property, otherwise throw it.
function executeWork(work, async, throws) {
  if (typeof async === 'function') { // Async
    blocking.submit(function() {
      var result = work();
      result = result || {};
      blocking.unblock(async)( result.err, result.result );
    });
  } else { // Sync
    var result = work();
    result = result || {};
    if (result.err) {
      if (throws) throw result.err;
      else return result.err;
    }
    return result.result;
  }
}

binding.FSInitialize = function(stats) {
  // fs.js uses this in "native" node.js to inform the C++ in
  // node_file.cc what JS function is used to construct an fs.Stat
  // object. For now, we'll just construct ours in JS and see how it goes.
  statsCtor = stats;
};

function buildStat(path, statf) {
  var err, stats,
      delegate = posix.allocateStat(),
      result = statf(delegate);

  if (result !== -1) {
    stats = new statsCtor(
      delegate.dev(),
      delegate.mode(),
      delegate.nlink(),
      delegate.uid(),
      delegate.gid(),
      delegate.rdev(),
      delegate.blockSize(),
      delegate.ino(),
      delegate.st_size(),
      delegate.blocks(),
      delegate.atime(),
      delegate.mtime(),
      delegate.ctime(),<commit_msg>Two more debug lines for CI.<commit_after>/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var nodyn      = require('nodyn'),
    util       = require('util'),
    blocking   = require('nodyn/blocking'),
    //posix      = Packages.jnr.posix.POSIXFactory.getPOSIX(new io.nodyn.posix.NodePosixHandler(), true),
    posix      = process._posix,
    Errno      = Packages.jnr.constants.platform.Errno,
    File       = Packages.java.io.File,
    Fs         = Packages.io.nodyn.fs.Fs,
    binding    = module.exports,
    statsCtor  = null;

// Executes work asynchronously if async is provided and is a function -
// otherwise, just executes the work and returns the result. If executing
// async and successful, the callback function is executed on the next tick.
// If there is an error and the throws param is falsy just returns the
// result.err property, otherwise throw it.
function executeWork(work, async, throws) {
  if (typeof async === 'function') { // Async
    blocking.submit(function() {
      var result = work();
      result = result || {};
      blocking.unblock(async)( result.err, result.result );
    });
  } else { // Sync
    var result = work();
    result = result || {};
    if (result.err) {
      if (throws) throw result.err;
      else return result.err;
    }
    return result.result;
  }
}

binding.FSInitialize = function(stats) {
  // fs.js uses this in "native" node.js to inform the C++ in
  // node_file.cc what JS function is used to construct an fs.Stat
  // object. For now, we'll just construct ours in JS and see how it goes.
  statsCtor = stats;
};

function buildStat(path, statf) {
  var err, stats,
      delegate = posix.allocateStat(),
      result = statf(delegate);

  console.log( "buildStat.result: " + result );
  console.log( "buildStat.errno: " + posix.errno() );

  if (result !== -1) {
    stats = new statsCtor(
      delegate.dev(),
      delegate.mode(),
      delegate.nlink(),
      delegate.uid(),
      delegate.gid(),
      delegate.rdev(),
      delegate.blockSize(),
      delegate.ino(),
      delegate.st_size(),
      delegate.blocks(),
      delegate.atime(),
      delegate.mtime(),
      delegate.ctime(),
{'fraction_non_alphanumeric': 0.11581709145427287, 'fraction_numerical': 0.003373313343328336, 'mean_word_length': 2.7505270555165144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1446011', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1527, 'n_words': 538}