Skip to content

Commit

Permalink
Merge pull request #2897 from avalonmediasystem/develop
Browse files Browse the repository at this point in the history
6.4rc3
  • Loading branch information
bkeese authored Mar 29, 2018
2 parents 9912928 + 789c278 commit 9c1fa34
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Ignore bundler config.
/.bundle
vendor/bundle

# Ignore the default SQLite database.
/db/*.sqlite3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
# Core rails
gem 'rails', '4.2.9'
gem 'sqlite3'
gem 'bootsnap', require: false

# Assets
gem 'coffee-rails', '~> 4.1.0'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ GEM
blacklight (~> 6.0)
cancancan (~> 1.8)
deprecation (~> 1.0)
bootsnap (1.2.1)
msgpack (~> 1.0)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
Expand Down Expand Up @@ -857,6 +859,7 @@ DEPENDENCIES
aws-sdk-rails
bixby
blacklight (= 6.11.0)
bootsnap
bootstrap-toggle-rails!
bootstrap_form
browse-everything (~> 0.13.0)
Expand Down
1 change: 1 addition & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup'
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171120190443) do
ActiveRecord::Schema.define(version: 20171130201127) do

create_table "annotations", force: :cascade do |t|
t.string "uuid"
Expand Down
52 changes: 33 additions & 19 deletions lib/avalon/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,49 @@

module Avalon
module Batch
class Error < ::Exception; end
class IncompletePackageError < Error; end

# Breaking the next method up further would only obscure logic
# rubocop:disable Metrics/MethodLength
def self.find_open_files(files, base_directory = '.')
args = files.collect { |p| %{"#{p}"} }.join(' ')
found_files = []
lsof = find_lsof
unless lsof
Rails.logger.warn('lsof missing; continuing without open file checking')
return found_files
end

args = files.collect { |p| %("#{p}") }.join(' ')
Dir.chdir(base_directory) do
result = []
begin
Timeout.timeout(5) do
status = `/usr/sbin/lsof -Fcpan0 #{args}`
statuses = status.split(/[\u0000\n]+/)
statuses.in_groups_of(4) do |group|
file_status = Hash[group.compact.collect { |s| [s[0].to_sym,s[1..-1]] }]
if file_status.has_key?(:n) and File.file?(file_status[:n]) and
(file_status[:a] =~ /w/ or file_status[:c] == 'scp')
result << file_status[:n]
end
end
output = `#{lsof} -Fcpan0 #{args}`
found_files = extract_files_from_lsof_output(output)
end
rescue Errno::ENOENT
# lsof doesn't exist so bail
Rails.logger.warn('lsof missing; continuing without open file checking')
rescue Timeout::Error
# lsof didn't return so bail
Rails.logger.warn('lsof blocking; continuing without open file checking')
end
result
end
found_files
end
# rubocop:enable Metrics/MethodLength

def self.find_lsof
(['/usr/sbin', '/usr/bin'] + ENV['PATH'].split(File::PATH_SEPARATOR))
.map { |path| "#{path}/lsof" }.find do |executable|
File.executable?(executable)
end
end

def self.extract_files_from_lsof_output(output)
found_files = []
statuses = output.split(/[\u0000\n]+/)
statuses.in_groups_of(4) do |group|
file_status = Hash[group.compact.collect { |s| [s[0].to_sym, s[1..-1]] }]
if file_status.key?(:n) && File.file?(file_status[:n]) &&
(file_status[:a] =~ /w/ || file_status[:c] == 'scp')
found_files << file_status[:n]
end
end
found_files
end
end
end

0 comments on commit 9c1fa34

Please sign in to comment.