Sha256: 5c2fb68ef9ed9a90e058530506a5a42d59f3bd0a9893ed15cde11447828331fb

Contents?: true

Size: 711 Bytes

Versions: 6

Compression:

Stored size: 711 Bytes

Contents

# frozen_string_literal: true

require 'fileutils'

module KPM
  class Blob
    def initialize(value, tmp_dir)
      @tmp_dir = tmp_dir
      @blob_file = @tmp_dir + File::SEPARATOR + rand.to_s
      # Make sure directory is 'rx' for others to allow LOAD_FILE to work
      FileUtils.chmod('a+rx', @tmp_dir)
      store_value(value)
    end

    # On Macos systems, this will require defining a `secure_file_priv` config:
    #
    # e.g /usr/local/etc/my.cnf :
    # [mysqld]
    # ...
    # secure_file_priv=""
    def value
      "LOAD_FILE(\"#{@blob_file}\")"
    end

    private

    def store_value(value)
      File.open(@blob_file, 'wb') do |file|
        file.write(value)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kpm-0.10.6 lib/kpm/blob.rb
kpm-0.11.1 lib/kpm/blob.rb
kpm-0.10.5 lib/kpm/blob.rb
kpm-0.11.0 lib/kpm/blob.rb
kpm-0.10.4 lib/kpm/blob.rb
kpm-0.10.3 lib/kpm/blob.rb