diff --git a/up.rb b/up.rb index f14dcb4..83492cd 100755 --- a/up.rb +++ b/up.rb @@ -15,15 +15,11 @@ ARGV.each do |path| # add the dot here, so that if we get a file without dot, we don't have # to conditionally add the dot later on ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/) + # make sure ext isn't nil + ext = ext.nil? ? "" : ext content = open(path).read md5 = Digest::MD5.hexdigest(content) - # basically a glorified syntax sugar for (ext.nil? ? "" : ext) - begin - Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) - # we probably tried to add nil to a string ("ext" could possibly be nil) - rescue TypeError - Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5) - end + Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext) } end