• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.94
/app/models/dump_file.rb
1
require 'zlib'
1✔
2
require 'digest'
1✔
3
require 'rubygems/package'
1✔
4

5
class DumpFile < ActiveRecord::Base
1✔
6
  belongs_to :dump
1✔
7
  enum :index_status, { enqueued: 0, started: 1, done: 2 }
1✔
8

9
  enum :dump_file_type, {
1✔
10
    bib_records: 1,
11
    updated_records: 2,
12
    recap_records: 3,
13
    recap_records_full: 4,
14
    log_file: 5,
15
    new_records: 6,
16
    merged_ids: 7,
17
    bib_ids: 8,
18
    recap_records_full_metadata: 9
19
  }
20

21
  after_create do
1✔
UNCOV
22
    self.path = generate_fp if path.nil?
×
UNCOV
23
    save
×
24
  end
25

26
  before_save do
1✔
UNCOV
27
    unless path.nil? || !File.exist?(path) || md5.present?
×
UNCOV
28
      self.md5 = File.open(path, 'rb') do |io|
×
29
        # nosemgrep
UNCOV
30
        digest = Digest::MD5.new
×
UNCOV
31
        buf = ''
×
UNCOV
32
        digest.update(buf) while io.read(4096, buf)
×
UNCOV
33
        digest
×
34
      end
35
    end
36
  end
37

38
  before_destroy do
1✔
UNCOV
39
    File.delete(path) if File.exist?(path)
×
40
  end
41

42
  def recap_record_type?
1✔
UNCOV
43
    self.recap_records? || self.recap_records_full?
×
44
  end
45

46
  def zipped?
1✔
UNCOV
47
    path.ends_with?('.gz')
×
48
  end
49

50
  def zip
1✔
UNCOV
51
    unless zipped?
×
UNCOV
52
      gz_path = "#{path}.gz"
×
UNCOV
53
      uncompressed_path = path
×
UNCOV
54
      Zlib::GzipWriter.open(gz_path) do |gz|
×
UNCOV
55
        File.open(uncompressed_path) do |fp|
×
UNCOV
56
          while chunk = fp.read(16 * 1024)
×
UNCOV
57
            gz.write chunk
×
58
          end
59
        end
UNCOV
60
        gz.close
×
61
      end
UNCOV
62
      self.path = gz_path
×
UNCOV
63
      File.delete(uncompressed_path)
×
UNCOV
64
      save
×
65
    end
UNCOV
66
    self
×
67
  end
68

69
  def unzip
1✔
UNCOV
70
    if zipped?
×
UNCOV
71
      uncompressed_path = path.sub(/\.gz$/, '')
×
UNCOV
72
      gz_path = path
×
73

UNCOV
74
      Zlib::GzipReader.open(gz_path) do |gz|
×
UNCOV
75
        File.open(uncompressed_path, 'wb') do |fp|
×
UNCOV
76
          while chunk = gz.read(16 * 1024)
×
UNCOV
77
            fp.write chunk
×
78
          end
79
        end
UNCOV
80
        gz.close
×
81
      end
82

UNCOV
83
      self.path = uncompressed_path
×
UNCOV
84
      File.delete(gz_path)
×
UNCOV
85
      save
×
86
    end
UNCOV
87
    self
×
88
  end
89

90
  def generate_fp
1✔
UNCOV
91
    File.join(MARC_LIBERATION_CONFIG['data_dir'], Time.now.to_i.to_s)
×
92
  end
93

94
  # Alma files are tarred and g-zipped, so you have to do both.
95
  def tar_decompress_file
1✔
UNCOV
96
    tar_reader.each.map do |entry|
×
UNCOV
97
      Tempfile.create(decompressed_filename(entry), binmode: true) do |decompressed_tmp|
×
UNCOV
98
        decompressed_file = write_chunks(entry, decompressed_tmp)
×
UNCOV
99
        entry.close
×
UNCOV
100
        yield(decompressed_file)
×
101
      end
102
    end
103
  end
104

105
  def tar_reader
1✔
UNCOV
106
    tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(path))
×
UNCOV
107
    tar_extract.tap(&:rewind)
×
108
  end
109

110
  def write_chunks(entry, temp_file)
1✔
UNCOV
111
    while (chunk = entry.read(16 * 1024))
×
UNCOV
112
      temp_file.write chunk
×
113
    end
UNCOV
114
    temp_file.tap(&:rewind)
×
115
  end
116

117
  def decompressed_filename(entry)
1✔
UNCOV
118
    file_name, decompress_extension = entry.full_name.split('.')
×
UNCOV
119
    decompress_extension ||= 'xml'
×
UNCOV
120
    ["full_reindex_file_unzip_#{file_name}", '.' + decompress_extension]
×
121
  end
122
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc