<commit_before>module Owlsync
  class Resource
    attr_accessor :dns_name, :user_name, :identityfile, :rsync_options, :updated, :release_path
    attr_reader  :source_path

    def initialize(dns_name)
      config = Owlsync.config
      self.dns_name = dns_name
      self.identityfile = config.ssh_key
      self.user_name = config.ssh_user
      self.rsync_options = config.rsync_options
      self.source_path = config.source_path
      self.release_path = config.release_path
      self.updated = false
    end

    def source_path=(path)
      @source_path =  path_fixed(path)
    end

    def rsync
      now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
      unless updated?
        cmd = "rsync #{rsync_options} -e 'ssh -i #{identityfile}' #{source_path} #{user_name}@#{dns_name}:#{release_path}"
        self.updated = system(cmd)

        $stdout.puts "[#{now}]: #{cmd}"
      else
        $stdout.puts "[#{now}]: Already updated."
      end
    rescue => e
      $stderr.puts "[#{now}][Error]: #{e}"
    end

    private

    def path_fixed(path)<commit_msg>Add ssh options StrictHostKeyChecking.<commit_after>module Owlsync
  class Resource
    attr_accessor :dns_name, :user_name, :identityfile, :rsync_options, :updated, :release_path
    attr_reader  :source_path

    def initialize(dns_name)
      config = Owlsync.config
      self.dns_name = dns_name
      self.identityfile = config.ssh_key
      self.user_name = config.ssh_user
      self.rsync_options = config.rsync_options
      self.source_path = config.source_path
      self.release_path = config.release_path
      self.updated = false
    end

    def source_path=(path)
      @source_path =  path_fixed(path)
    end

    def rsync
      return if updated?

      now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
      cmd = "rsync #{rsync_options} -e 'ssh -i #{identityfile} -o StrictHostKeyChecking=no' #{source_path} #{user_name}@#{dns_name}:#{release_path}"

      if self.updated = system(cmd)
        $stdout.puts "[#{now}]: #{cmd}."
      else
        $stderr.puts "[#{now}][Failed]: #{cmd}."
      end
    rescue => e
      $stderr.puts "[#{now}][Error]: #{e}"
    end

    private

    def path_fixed(path)
{'fraction_non_alphanumeric': 0.12922374429223743, 'fraction_numerical': 0.0, 'mean_word_length': 2.8778761061946905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1515424', 'n_tokens_mistral': 765, 'n_tokens_neox': 748, 'n_words': 151}