<commit_before>require "tempfile"
require "ecr/macros"
require "./carcin"

class SandboxDefinition
  json_mapping({
    name:                     String,
    versions:                 Array(String),
    dependencies:             Array(String),
    aur_dependencies:         Array(String),
    timeout:                  Int32,
    memory:                   {type: Int32, nilable: true},
    allowed_programs:         Array(String),
    allowed_failing_programs: Array(String)
  }, true)
end

class SandboxWrapper
  getter path
  getter name
  getter timeout
  getter memory
  getter whitelist
  ecr_file "#{__DIR__}/carcin/sandbox_wrapper.ecr"

  def initialize(@path, @name, @timeout, @memory, @whitelist)
  end
end

lib LibC
  fun getuid() : Int32
  fun setuid(uid : Int32) : Int32
end

if LibC.getuid != 0
  abort "This command must be run with root permissions."
end

def has_command command
  system("which #{command} 2>/dev/null >/dev/null")
end

{"btrfs", "pacstrap", "arch-chroot", "makepkg", "updpkgsums", "yaourt"}.each do |tool|
  unless has_command(tool)
    abort "This command needs the #{tool} tool."
  end
end

fs_type = `df -T #{Carcin::SANDBOX_BASEPATH}`.lines.last.split[1]
unless fs_type == "btrfs"
  abort "#{Carcin::SANDBOX_BASEPATH} must be on a btrfs filesystem."
end

def create_subvolume path
  Dir.mkdir_p File.dirname(path)
  system("btrfs subvolume create #{path}")
end

def create_snapshot of, path
  Dir.mkdir_p File.dirname(path)
  system("btrfs subvolume snapshot #{of} #{path}")<commit_msg>don't run sandbox manager without playpen<commit_after>require "tempfile"
require "ecr/macros"
require "./carcin"

class SandboxDefinition
  json_mapping({
    name:                     String,
    versions:                 Array(String),
    dependencies:             Array(String),
    aur_dependencies:         Array(String),
    timeout:                  Int32,
    memory:                   {type: Int32, nilable: true},
    allowed_programs:         Array(String),
    allowed_failing_programs: Array(String)
  }, true)
end

class SandboxWrapper
  getter path
  getter name
  getter timeout
  getter memory
  getter whitelist
  ecr_file "#{__DIR__}/carcin/sandbox_wrapper.ecr"

  def initialize(@path, @name, @timeout, @memory, @whitelist)
  end
end

lib LibC
  fun getuid() : Int32
  fun setuid(uid : Int32) : Int32
end

if LibC.getuid != 0
  abort "This command must be run with root permissions."
end

def has_command command
  system("which #{command} 2>/dev/null >/dev/null")
end

{"btrfs", "pacstrap", "arch-chroot", "makepkg", "updpkgsums", "yaourt", "playpen"}.each do |tool|
  unless has_command(tool)
    abort "This command needs the #{tool} tool."
  end
end

fs_type = `df -T #{Carcin::SANDBOX_BASEPATH}`.lines.last.split[1]
unless fs_type == "btrfs"
  abort "#{Carcin::SANDBOX_BASEPATH} must be on a btrfs filesystem."
end

def create_subvolume path
  Dir.mkdir_p File.dirname(path)
  system("btrfs subvolume create #{path}")
end

def create_snapshot of, path
  Dir.mkdir_p File.dirname(path)
  system("btrfs subvolume snapshot #{of} #{path}")
{'fraction_non_alphanumeric': 0.11474878444084279, 'fraction_numerical': 0.008427876823338737, 'mean_word_length': 3.2920723226703754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '454499', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1028, 'n_words': 283}