From df6d06102c7a6b1ceaf2985eb859577fe9ff576b Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Thu, 22 Jan 2015 18:14:34 -0800 Subject: [PATCH] Convert deprecated File.exists? to File.exist? --- code/adminoper.rb | 8 ++++---- code/cleaner_script.rb | 6 +++--- code/main.rb | 10 +++++----- code/overrides.rb | 2 +- code/queue.rb | 24 ++++++++++++------------ code/relay_script.rb | 4 ++-- code/rq.rb | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/code/adminoper.rb b/code/adminoper.rb index 8dc8654..94a0c80 100644 --- a/code/adminoper.rb +++ b/code/adminoper.rb @@ -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' @@ -55,7 +55,7 @@ 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 @@ -63,7 +63,7 @@ def create_file(file) end def delete_file(file) - if File.exists?(file) + if File.exist?(file) count = File.unlink(file) rescue 0 count > 0 else diff --git a/code/cleaner_script.rb b/code/cleaner_script.rb index d9662f0..832a4dc 100755 --- a/code/cleaner_script.rb +++ b/code/cleaner_script.rb @@ -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" @@ -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 @@ -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 diff --git a/code/main.rb b/code/main.rb index 23723d4..3ebbb7f 100644 --- a/code/main.rb +++ b/code/main.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/code/overrides.rb b/code/overrides.rb index 135f002..97e5991 100644 --- a/code/overrides.rb +++ b/code/overrides.rb @@ -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 diff --git a/code/queue.rb b/code/queue.rb index d18f04a..479f221 100644 --- a/code/queue.rb +++ b/code/queue.rb @@ -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 @@ -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' @@ -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 @@ -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 @@ -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']}" @@ -916,12 +916,12 @@ 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']) @@ -929,7 +929,7 @@ def attach_msg(msg) # 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 @@ -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) @@ -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 diff --git a/code/relay_script.rb b/code/relay_script.rb index 28609d4..b762145 100755 --- a/code/relay_script.rb +++ b/code/relay_script.rb @@ -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?('.') } @@ -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}") } diff --git a/code/rq.rb b/code/rq.rb index 731af8d..0fd7b7a 100644 --- a/code/rq.rb +++ b/code/rq.rb @@ -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'])