Skip to content

Commit

Permalink
Convert deprecated File.exists? to File.exist?
Browse files Browse the repository at this point in the history
  • Loading branch information
sodabrew committed Jan 23, 2015
1 parent d09a9c1 commit df6d061
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions code/adminoper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def status
end

def update!
if File.exists?(@down_file)
if File.exist?(@down_file)
@admin_status = 'DOWN'
elsif File.exists?(@pause_file)
elsif File.exist?(@pause_file)
@admin_status = 'PAUSE'
else
@admin_status = 'UP'
Expand Down Expand Up @@ -55,15 +55,15 @@ def set_oper_status(stat)
private

def create_file(file)
unless File.exists?(file)
unless File.exist?(file)
File.new(file, File::CREAT, 0644) rescue nil
else
true
end
end

def delete_file(file)
if File.exists?(file)
if File.exist?(file)
count = File.unlink(file) rescue 0
count > 0
else
Expand Down
6 changes: 3 additions & 3 deletions code/cleaner_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def rm_logs_older_than(qname, regex, hours)
end

def mv_logs(qname)
if File.exists?("#{qname}/queue.log")
if File.exist?("#{qname}/queue.log")
a=Time.now
b = sprintf("%s%.2d%.2d.%.2d:%.2d" ,a.year, a.month, a.day, a.hour, a.min)
puts "status: moving #{qname}/queue.log"
Expand All @@ -76,7 +76,7 @@ def mv_logs(qname)
def remove_old(qname, days)
clean_queues = ["/done", "/relayed", "/prep", "/queue"]
clean_queues.each do |cq|
if File.exists?(qname + cq)
if File.exist?(qname + cq)

# go by directories and remove any day dir > days + 1
# then go into the hour dirs and remove by time
Expand Down Expand Up @@ -145,7 +145,7 @@ def trim_relay(qpath, num)
queues = listq(basedir)
else
queues = [basedir + "/queue/" + ENV['RQ_PARAM1']]
if not File.exists?queues[0]
if not File.exist?queues[0]
fail_hard("the specified queue #{queues} does not exist")
end
end
Expand Down
10 changes: 5 additions & 5 deletions code/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_queueclient(name)
# No RQ should be connecting to another box's relay
# However, users need the web ui to interact, so we think
# this is safe and good for debugging/visiblity
if File.exists?("./config/rq_router_rules.rb")
if File.exist?("./config/rq_router_rules.rb")
if not ['relay', 'cleaner'].include?(name)
name = 'rq_router'
end
Expand Down Expand Up @@ -347,7 +347,7 @@ def flash(type, msg)
get '/q/:name/config.json' do
path = "./queue/#{params['name']}/config.json"

if not File.exists? path
if not File.exist? path
throw :halt, [404, "404 - Queue config for '#{params['name']}' not found"]
end

Expand Down Expand Up @@ -565,7 +565,7 @@ def flash(type, msg)

# send_file does this check, but we provide a much more contextually relevant error
# TODO: finer grained checking (que, msg_id exists, etc.)
if not File.exists? path
if not File.exist? path
throw :halt, [404, "404 - Message ID log '#{params['log_name']}' not found"]
end

Expand All @@ -590,7 +590,7 @@ def flash(type, msg)

# send_file does this check, but we provide a much more contextually relevant error
# TODO: finer grained checking (que, msg_id exists, etc.)
if not File.exists? path
if not File.exist? path
throw :halt, [404, "404 - Message ID attachment '#{params['attach_name']}' not found"]
end

Expand All @@ -615,7 +615,7 @@ def flash(type, msg)

# send_file does this check, but we provide a much more contextually relevant error
# TODO: finer grained checking (que, msg_id exists, etc.)
if not File.exists? path
if not File.exist? path
throw :halt, [404, "404 - Message ID attachment '#{params['attach_name']}' not found"]
end

Expand Down
2 changes: 1 addition & 1 deletion code/overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(name, read_file = true)
end

def get_json(path)
if File.exists? path
if File.exist? path
begin
@data = JSON.parse(File.read(path))
rescue
Expand Down
24 changes: 12 additions & 12 deletions code/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def run_queue_script!(msg)

basename = File.join(@queue_path, 'run', msg_id)
job_path = File.expand_path(File.join(basename, 'job'))
Dir.mkdir(job_path) unless File.exists?(job_path)
Dir.mkdir(job_path) unless File.exist?(job_path)

# Identify executable to run, if there is no script, go oper down
# Also, fix an old issue where we didn't deref the symlink when executing a script
Expand Down Expand Up @@ -584,7 +584,7 @@ def que(msg, from_state = 'prep')
# Read in full message
msg = get_message(msg, from_state)
basename = msg['path']
return false unless File.exists? basename
return false unless File.exist? basename
newname = File.join(@queue_path, 'que', msg_id)
File.rename(basename, newname)
msg['state'] = 'que'
Expand Down Expand Up @@ -725,7 +725,7 @@ def msg_state_prep?(msg)
return false unless @prep.include?(msg_id)

basename = File.join(@queue_path, 'prep', msg_id)
unless File.exists?(basename)
unless File.exist?(basename)
$log.warn("WARNING - serious queue inconsistency #{msg_id}")
$log.warn("WARNING - #{msg_id} in memory but not on disk")
return false
Expand Down Expand Up @@ -757,7 +757,7 @@ def msg_state(msg, options={:consistency => true})
basename ||= File.join(@queue_path, state, msg_id)

if options[:consistency]
unless File.exists?(basename)
unless File.exist?(basename)
$log.warn("WARNING - serious queue inconsistency #{msg_id}")
$log.warn("WARNING - #{msg_id} in memory but not on disk")
return false
Expand Down Expand Up @@ -858,7 +858,7 @@ def get_message(params, state,
msg['path'] = basename
msg['status'] = state
msg['state'] = state
if File.exists?(basename + "/status")
if File.exist?(basename + "/status")
xtra_data = File.read(basename + "/status")
xtra_status = JSON.parse(xtra_data)
msg['status'] += " - #{xtra_status['job_status']}"
Expand Down Expand Up @@ -916,20 +916,20 @@ def attach_msg(msg)
result = [false, 'Unknown error']
begin
basename = File.join(@queue_path, 'prep', msg_id)
return [false, "No message on disk"] unless File.exists? basename
return [false, "No message on disk"] unless File.exist? basename

#TODO: deal with symlinks
# simple early check, ok, now check for pathname
return [false, "Invalid pathname, must be normalized #{msg['pathname']} (ie. must start with /"] unless msg['pathname'].start_with?("/")
return [false, "No such file #{msg['pathname']} to attach to message"] unless File.exists?(msg['pathname'])
return [false, "No such file #{msg['pathname']} to attach to message"] unless File.exist?(msg['pathname'])
return [false, "Attachment currently cannot be a directory #{msg['pathname']}"] if File.directory?(msg['pathname'])
return [false, "Attachment currently cannot be read: #{msg['pathname']}"] unless File.readable?(msg['pathname'])
return [false, "Attachment currently not of supported type: #{msg['pathname']}"] unless File.file?(msg['pathname'])


# simple check for attachment dir
attach_path = basename + '/attach/'
Dir.mkdir(attach_path) unless File.exists?(attach_path)
Dir.mkdir(attach_path) unless File.exist?(attach_path)

# OK do we have a name?
# Try that first, else use basename
Expand Down Expand Up @@ -988,14 +988,14 @@ def del_attach_msg(msg)
result = [false, 'Unknown error']
begin
basename = File.join(@queue_path, 'prep', msg_id)
return [false, "No message on disk"] unless File.exists? basename
return [false, "No message on disk"] unless File.exist? basename

# simple check for attachment dir
attach_path = basename + '/attach/'
return [false, "No attach directory for msg"] unless File.exists?(attach_path)
return [false, "No attach directory for msg"] unless File.exist?(attach_path)

new_path = attach_path + attach_name
return [false, "No attachment with that named for msg"] unless File.exists?(new_path)
return [false, "No attachment with that named for msg"] unless File.exist?(new_path)

File.unlink(new_path)

Expand Down Expand Up @@ -1465,7 +1465,7 @@ def handle_child_close(msg, exit_status=nil)
# Move to relay dir and update in-memory data structure
begin
basename = File.join(@queue_path, 'run', msg_id)
raise unless File.exists? basename
raise unless File.exist? basename
remove_msg_process_id(msg_id)
if ['done', 'relayed'].include? new_state
# store message since it made it to done and we want the 'dups' field to live
Expand Down
4 changes: 2 additions & 2 deletions code/relay_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def file_md5(path)
new_short_msg_id = new_msg_id[/\/q\/[^\/]+\/([^\/]+)/, 1]

# Idempotently attach any attachments
if File.exists?('../attach')
if File.exist?('../attach')
log("attempting sending attach")
entries = Dir.entries('../attach').reject { |e| e.start_with?('.') }

Expand Down Expand Up @@ -349,7 +349,7 @@ def file_md5(path)
log("attempting local send attach")

# Idempotently attach any attachments
if File.exists?('../attach')
if File.exist?('../attach')
entries = Dir.entries('../attach').reject { |e| e.start_with?('.') }

fnames = entries.select { |e| File.file?("../attach/#{e}") }
Expand Down
2 changes: 1 addition & 1 deletion code/rq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def cmd_prepmesg(args)

def check_attachment(msg)
# simple early check, ok, now check for pathname
return [false, "No such file #{msg['pathname']} to attach to message"] unless File.exists?(msg['pathname'])
return [false, "No such file #{msg['pathname']} to attach to message"] unless File.exist?(msg['pathname'])
return [false, "Attachment currently cannot be a directory #{msg['pathname']}"] if File.directory?(msg['pathname'])
return [false, "Attachment currently cannot be read: #{msg['pathname']}"] unless File.readable?(msg['pathname'])
return [false, "Attachment currently not of supported type: #{msg['pathname']}"] unless File.file?(msg['pathname'])
Expand Down

0 comments on commit df6d061

Please sign in to comment.