<commit_before>/**
 * This file is part of the CernVM File System.
 */

#include <gtest/gtest.h>

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <ctime>

#include "libcvmfs.h"
#include "statistics.h"
#include "util/posix.h"
#include "xattr.h"

#include "shrinkwrap/fs_traversal.h"
#include "shrinkwrap/fs_traversal_interface.h"
#include "shrinkwrap/fs_traversal_libcvmfs.h"
#include "shrinkwrap/posix/interface.h"
#include "shrinkwrap/util.h"

#include "testutil_shrinkwrap.h"

const mode_t kModeBitmask = (S_IRWXO | S_IRWXG | S_IRWXU);

using namespace std;  // NOLINT

struct FsTest {
  struct fs_traversal *interface;
  const char *repo;
  const char *data;
};

class T_FsInterface : public ::testing::TestWithParam<struct FsTest *> {
 protected:
  virtual void SetUp() {
    Init();
  }

  virtual void TearDown() {
    // TODO(steuber): Where to free?
    Fin();
    // delete fs_instance_->interface;
  }

  void Init() {
    fs_instance_ = GetParam();
    const char *repo = fs_instance_->repo;
    if (repo == NULL) {
      // Current working directory setup from testing environment
      repo = "./";
    }
    context_ = fs_instance_->interface->initialize(
      repo,
      repo,
      fs_instance_->data, NULL, 4);
    fs_instance_->interface->context_ = context_;
    supports_xattrs_ = SupportsXattrs(".");
  }

  void Fin() {
    fs_instance_->interface->finalize(context_);
    context_ = NULL;
  }

  void Restart() {
    Fin();
    Init();
  }

  /**
   * Creates the following entries:
   * DIRECTORIES:
   * /[prefix]-foo
   * /[prefix]-foo/bar
   * /[prefix]-bar
   * /[prefix]-bar/foobar
   * /[prefix]-bar/foobar/foobar
   * /[prefix]-bar/test
   *
   * FILES:
   * /[prefix]-foo.txt -> ident1
   * /[prefix]-bar.txt -> ident2
   * /[prefix]-foo/bar/foobar1.txt -> ident1
   * /[prefix]-foo/bar/foobar2.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   *
   * SYMLINKS:
   * ./[prefix]-symlink1 -> ./foo
   * ./[prefix]-foo/bar/symlink2 -> ./foobar
   */
  void MakeTestFiles(
    std::string prefix,
    std::string *ident1,
    std::string *ident2)
  {
    // File Content1
    std::string content1 = prefix + ": Hello world!\nHello traversal!";
    shash::Any content1_hash(shash::kSha1);
    shash::HashString(content1, &content1_hash);

    ASSERT_TRUE(SafeWriteToFile(content1, "temp.data", 0600));
    shash::Any cvm_checksum = shash::Any(shash::kSha1);
    shash::HashFile("temp.data", &cvm_checksum);
    ASSERT_STREQ(cvm_checksum.ToString().c_str(),
                 content1_hash.ToString().c_str());

    // File Content2
    std::string content2 = prefix + ": Hello traversal!\nHello world!";
    shash::Any content2_hash(shash::kSha1);
    shash::HashString(content2, &content2_hash);

    // File meta data 1
    XattrList *xlistdir = NULL;
    XattrList *xlist1 = NULL;
    XattrList *xlist2 = NULL;
    if (supports_xattrs_) {
      xlistdir = CreateSampleXattrlist(prefix);
      xlist1 = CreateSampleXattrlist(prefix);
      xlist2 = CreateSampleXattrlist(prefix + "-2");
    }

    struct cvmfs_attr *stat_values_dir = CreateSampleStat(
      ("/" + prefix + "-bar.txt").c_str(),
      10, 0770, 0, xlistdir, &content1_hash);
    struct cvmfs_attr *stat_values1 = CreateSampleStat(
      ("/" + prefix + "-foo.txt").c_str(),
      10, 0770, 0, xlist1, &content1_hash);<commit_msg>fix shrinkwrap unit test errors<commit_after>/**
 * This file is part of the CernVM File System.
 */

#include <gtest/gtest.h>

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <ctime>

#include "libcvmfs.h"
#include "statistics.h"
#include "util/posix.h"
#include "xattr.h"

#include "shrinkwrap/fs_traversal.h"
#include "shrinkwrap/fs_traversal_interface.h"
#include "shrinkwrap/fs_traversal_libcvmfs.h"
#include "shrinkwrap/posix/interface.h"
#include "shrinkwrap/util.h"

#include "testutil_shrinkwrap.h"

const mode_t kModeBitmask = (S_IRWXO | S_IRWXG | S_IRWXU);

using namespace std;  // NOLINT

struct FsTest {
  struct fs_traversal *interface;
  const char *repo;
  const char *data;
};

class T_FsInterface : public ::testing::TestWithParam<struct FsTest *> {
 protected:
  virtual void SetUp() {
    Init();
  }

  virtual void TearDown() {
    // TODO(steuber): Where to free?
    Fin();
    // delete fs_instance_->interface;
  }

  void Init() {
    fs_instance_ = GetParam();
    const char *repo = fs_instance_->repo;
    if (repo == NULL) {
      // Current working directory setup from testing environment
      repo = "./";
    }
    context_ = fs_instance_->interface->initialize(
      repo,
      repo,
      fs_instance_->data, NULL, 4);
    fs_instance_->interface->context_ = context_;
    supports_xattrs_ = SupportsXattrs(".");
  }

  void Fin() {
    fs_instance_->interface->finalize(context_);
    context_ = NULL;
  }

  void Restart() {
    Fin();
    Init();
  }

  /**
   * Creates the following entries:
   * DIRECTORIES:
   * /[prefix]-foo
   * /[prefix]-foo/bar
   * /[prefix]-bar
   * /[prefix]-bar/foobar
   * /[prefix]-bar/foobar/foobar
   * /[prefix]-bar/test
   *
   * FILES:
   * /[prefix]-foo.txt -> ident1
   * /[prefix]-bar.txt -> ident2
   * /[prefix]-foo/bar/foobar1.txt -> ident1
   * /[prefix]-foo/bar/foobar2.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   * /[prefix]-foo/bar/foobar3.txt -> ident1
   *
   * SYMLINKS:
   * ./[prefix]-symlink1 -> ./foo
   * ./[prefix]-foo/bar/symlink2 -> ./foobar
   */
  void MakeTestFiles(
    std::string prefix,
    std::string *ident1,
    std::string *ident2)
  {
    // File Content1
    std::string content1 = prefix + ": Hello world!\nHello traversal!";
    shash::Any content1_hash(shash::kSha1);
    shash::HashString(content1, &content1_hash);

    // File Content2
    std::string content2 = prefix + ": Hello traversal!\nHello world!";
    shash::Any content2_hash(shash::kSha1);
    shash::HashString(content2, &content2_hash);

    // File meta data 1
    XattrList *xlistdir = NULL;
    XattrList *xlist1 = NULL;
    XattrList *xlist2 = NULL;
    if (supports_xattrs_) {
      xlistdir = CreateSampleXattrlist(prefix);
      xlist1 = CreateSampleXattrlist(prefix);
      xlist2 = CreateSampleXattrlist(prefix + "-2");
    }

    struct cvmfs_attr *stat_values_dir = CreateSampleStat(
      ("/" + prefix + "-bar.txt").c_str(),
      10, 0770, 0, xlistdir, &content1_hash);
    struct cvmfs_attr *stat_values1 = CreateSampleStat(
      ("/" + prefix + "-foo.txt").c_str(),
      10, 0770, 0, xlist1, &content1_hash);
{'fraction_non_alphanumeric': 0.1560410164957646, 'fraction_numerical': 0.016792985584782285, 'mean_word_length': 3.1237745098039214, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 55, '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': '5826961', 'n_tokens_mistral': 2565, 'n_tokens_neox': 2443, 'n_words': 475}