Sha256: 7bf13f4d653db5e14470681d7bd8bda30693a4efd87dae5aacca166408093846

Contents?: true

Size: 1.57 KB

Versions: 39

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

require 'avm/instances/data/unit'

module Avm
  module Instances
    module Data
      class FilesUnit < ::Avm::Instances::Data::Unit
        EXTENSION = '.tar.gz'

        enable_listable
        lists.add_symbol :option, :sudo_user

        common_constructor :instance, :fs_path_subpath, :options, default: [{}],
                                                                  super_args: -> { [instance] } do
          self.fs_path_subpath = fs_path_subpath.to_pathname
          self.options = self.class.lists.option.hash_keys_validate!(options)
        end

        before_load :clear_files

        # @return [Pathname]
        def files_path
          fs_path_subpath
            .expand_path(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH))
        end

        def dump_command
          instance_command('tar', '-czf', '-', '-C', files_path, '.')
        end

        def load_command
          instance_command('tar', '-xzf', '-', '-C', files_path)
        end

        def clear_files
          infom "Removing all files under #{files_path}..."
          instance_command('mkdir', '-p', files_path).execute!
          instance_command('find', files_path, '-mindepth', 1, '-delete').execute!
        end

        # @return [EacRubyUtils::Envs::Command]
        def instance_command(*args)
          args = ['sudo', '-Hu', sudo_user] + args if sudo_user.present?
          instance.host_env.command(*args)
        end

        # @return [String, nil]
        def sudo_user
          options[OPTION_SUDO_USER]
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
eac_tools-0.60.0 sub/avm/lib/avm/instances/data/files_unit.rb
eac_tools-0.59.0 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.66.1 lib/avm/instances/data/files_unit.rb
eac_tools-0.58.0 sub/avm/lib/avm/instances/data/files_unit.rb
eac_tools-0.57.0 sub/avm/lib/avm/instances/data/files_unit.rb
eac_tools-0.56.1 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.66.0 lib/avm/instances/data/files_unit.rb
eac_tools-0.56.0 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.65.0 lib/avm/instances/data/files_unit.rb
eac_tools-0.55.7 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.64.2 lib/avm/instances/data/files_unit.rb
eac_tools-0.55.6 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.64.1 lib/avm/instances/data/files_unit.rb
eac_tools-0.55.5 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.64.0 lib/avm/instances/data/files_unit.rb
eac_tools-0.55.4 sub/avm/lib/avm/instances/data/files_unit.rb
avm-0.63.0 lib/avm/instances/data/files_unit.rb
eac_tools-0.55.3 sub/avm/lib/avm/instances/data/files_unit.rb
eac_tools-0.55.2 sub/avm/lib/avm/instances/data/files_unit.rb
eac_tools-0.55.1 sub/avm/lib/avm/instances/data/files_unit.rb