lib/rscm/path_converter.rb in rscm-0.2.1.1404 vs lib/rscm/path_converter.rb in rscm-0.3.0

- old
+ new

@@ -1,33 +1,26 @@ -require 'fileutils' -require 'rscm/logging' - WIN32 = RUBY_PLATFORM == "i386-mswin32" CYGWIN = RUBY_PLATFORM == "i386-cygwin" WINDOWS = WIN32 || CYGWIN - -# TODO: change to override IO.popen, using that neat trick we -# used in threadfile.rb (which is now gone) -def safer_popen(cmd, mode="r", expected_exit=0, &proc) - Log.info "Executing command: '#{cmd}'" - ret = IO.popen(cmd, mode, &proc) - exit_code = $? >> 8 - raise "#{cmd} failed with code #{exit_code} in #{Dir.pwd}. Expected exit code: #{expected_exit}" if exit_code != expected_exit - ret +if(WINDOWS) + HOMEDIR = RSCM::PathConverter.nativepath_to_filepath("#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}").gsub(/\\/, "/") +else + HOMEDIR = ENV['HOME'] end +require 'fileutils' +require 'rscm/logging' + def with_working_dir(dir) # Can't use Dir.chdir{ block } - will fail with multithreaded code. # http://www.ruby-doc.org/core/classes/Dir.html#M000790 # prev = Dir.pwd begin dir = File.expand_path(dir) - Log.info "Making directory: '#{dir}'" FileUtils.mkdir_p(dir) Dir.chdir(dir) - Log.info "In directory: '#{dir}'" yield ensure Dir.chdir(prev) end end @@ -40,11 +33,11 @@ path = File.expand_path(path) if(WIN32) path.gsub(/\//, "\\") elsif(CYGWIN) cmd = "cygpath --windows #{path}" - safer_popen(cmd) do |io| + Better.popen(cmd) do |io| cygpath = io.read.chomp escaped ? cygpath.gsub(/\\/, "\\\\\\\\") : cygpath end else path @@ -66,10 +59,10 @@ if(WIN32) path.gsub(/\//, "\\") elsif(CYGWIN) path = path.gsub(/\\/, "/") cmd = "cygpath --unix #{path}" - safer_popen(cmd) do |io| + Better.popen(cmd) do |io| io.read.chomp end else path end