lib/filbunke/client.rb in filbunke-1.5.3 vs lib/filbunke/client.rb in filbunke-1.6.0

- old
+ new

@@ -208,22 +208,30 @@ end def update_hdfs_file!(file, local_file_path) begin ::FileUtils.mkdir_p(::File.dirname(local_file_path)) - - hdfs_cmd = "rm -f #{local_file_path}.tmp; #{@repository.hadoop_binary} fs -copyToLocal #{file.url} #{local_file_path}.tmp &> /dev/null && mv #{local_file_path}.tmp #{local_file_path}" + ::FileUtils.rm_f("#{local_file_path}.tmp") + hdfs_cmd = "#{@repository.hadoop_binary} fs -copyToLocal #{file.url} #{local_file_path}.tmp" @logger.log "Trying to update #{local_file_path} with '#{hdfs_cmd}'" - system hdfs_cmd - - if $?.exitstatus == 0 then - return true + + pid, stdin, stdout, stderr = Open4::popen4 hdfs_cmd + ignored, status = Process::waitpid2 pid + + if status.exitstatus == 0 then + begin + ::FileUtils.mv "#{local_file_path}.tmp", local_file_path + return true + rescue StandardError => e + @logger.log "Failed to move hdfs file #{file.url}: #{e.message}" + return false + end else - @logger.log "Failed to update file #{file.url}!" + @logger.log "Failed to update hdfs file #{file.url}! Unable to execute #{hfds_cmd}" return false end rescue StandardError => e - @logger.log "Failed to update file #{file.url}: #{e.message}" + @logger.log "Failed to update hdfs file #{file.url}: #{e.message}" return false end end def write_file!(file_path, contents)