module Bosh::Cli
  class SortedReleaseArchiver
    def initialize(dir)
      @dir = dir
    end

    def archive(destination_file)
      Dir.chdir(@dir) do
        success = Kernel.system('tar', '-C', @dir, '-pczf', destination_file, *ordered_release_files, out: '/dev/null', err: '/dev/null')
        if !success
          raise InvalidRelease, 'Cannot create release tarball'
        end
      end
    end

    private

    def ordered_release_files
      ordered_release_files = ['./release.MF']
      license_files = Dir.entries('.') & ['LICENSE', 'NOTICE'].sort
      unless license_files.empty?
        ordered_release_files += license_files.map { |filename| "./#{filename}" }
      end
      ordered_release_files += ['./jobs', './packages']
      ordered_release_files
    end
  end
end

module Bosh::Cli
  class SortedReleaseArchiver
    def initialize(dir)
      @dir = dir
    end

    def archive(destination_file)
      Dir.chdir(@dir) do
        success = Kernel.system('tar', '-C', @dir, '-pczf', destination_file, *ordered_release_files, out: '/dev/null', err: '/dev/null')
        if !success
          raise InvalidRelease, 'Cannot create release tarball'
        end
      end
    end

    private

    def ordered_release_files
      ordered_release_files = ['./release.MF']
      license_files = (Dir.entries('.') & ['LICENSE', 'NOTICE']).sort
      unless license_files.empty?
        ordered_release_files += license_files.map { |filename| "./#{filename}" }
      end
      ordered_release_files += ['./jobs', './packages']
      ordered_release_files
    end
  end
end

Sort result of found files when creating release
Sort result of found files when creating release

[#111655044](https://www.pivotaltracker.com/story/show/111655044)

Signed-off-by: Maria Shaldibina <dc03896a0185453e5852a5e0f0fab6cbd2e026ff@pivotal.io>
