<commit_before>module BackupDirectoryHelper
  include BackupCommonHelper

  def backup_directories
    applications = node['cloudconductor']['applications']
    paths = applications.select(&dynamic?).map do |_, application|
      application[:parameters][:backup_directories] || []
    end

    paths.flatten
  end

  def s3_uri(name)
    s3 = node['backup_restore']['destinations']['s3']
    URI.join("s3://#{s3['bucket']}", File.join(s3['prefix'], 'directories', name, '/')).to_s
  end

  def syncer_definition
    commands = backup_directories.map do |path|
      name = Pathname.new(path).basename
      "`s3cmd sync #{path} #{s3_uri(name)}`"
    end

    commands.join("\n")
  end

  def restore_code
    commands = backup_directories.map do |path|
      name = Pathname.new(path).basename
      "s3cmd sync #{s3_uri(name)} #{path}"
    end<commit_msg>Return directory without subdirectory to suppress duplicate directory<commit_after>module BackupDirectoryHelper
  include BackupCommonHelper

  def backup_directories
    applications = node['cloudconductor']['applications']
    paths = applications.select(&dynamic?).map do |_, application|
      application[:parameters][:backup_directories] || []
    end

    paths.flatten
  end

  def s3_uri(name = '')
    s3 = node['backup_restore']['destinations']['s3']
    URI.join("s3://#{s3['bucket']}", File.join(s3['prefix'], 'directories', name, '/')).to_s
  end

  def syncer_definition
    commands = backup_directories.map do |path|
      "`s3cmd sync #{path} #{s3_uri}`"
    end

    commands.join("\n")
  end

  def restore_code
    commands = backup_directories.map do |path|
      name = Pathname.new(path).basename
      "s3cmd sync #{s3_uri(name)} #{path}"
    end
{'fraction_non_alphanumeric': 0.14351851851851852, 'fraction_numerical': 0.011574074074074073, 'mean_word_length': 3.925925925925926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3317741', 'n_tokens_mistral': 552, 'n_tokens_neox': 538, 'n_words': 112}