null+****@clear*****
null+****@clear*****
Tue Mar 13 16:38:01 JST 2012
SHIMADA Koji 2012-03-13 16:38:01 +0900 (Tue, 13 Mar 2012) New Revision: affc45150b11556144147d0b175172a8dce6b0dc Log: Fix problem when loga command call on windows console - revise how to check if working path is root path Modified files: lib/logaling/command/application.rb Modified: lib/logaling/command/application.rb (+27 -9) =================================================================== --- lib/logaling/command/application.rb 2012-03-13 13:27:24 +0900 (a09878e) +++ lib/logaling/command/application.rb 2012-03-13 16:38:01 +0900 (215b62a) @@ -308,21 +308,39 @@ module Logaling::Command end def find_dotfile - dir = Dir.pwd + onset_dir = Dir.pwd searched_path = [] - while(dir) do - path = File.join(dir, '.logaling') + until root_path? + working_dir = Dir.pwd + path = File.join(working_dir, '.logaling') if File.exist?(path) return path else - if dir != "/" - searched_path << dir - dir = File.dirname(dir) - else - raise(Logaling::CommandFailed, "Can't found .logaling in #{searched_path}") - end + searched_path << working_dir + Dir.chdir(File.dirname(working_dir)) end end + raise(Logaling::CommandFailed, "Can't found .logaling in #{searched_path}") + ensure + Dir.chdir(onset_dir) + end + + def windows? + RUBY_PLATFORM =~ /win32|mingw32/i + end + + def root_path? + if windows? + require 'Win32API' + cmd = Win32API.new('kernel32', 'GetCurrentDirectory', ['i', 'p'], 'i') + size = 256 + current_dir = " " * size + cmd.call(size, current_dir) + cmd = Win32API.new('shlwapi', 'PathIsRoot', 'p', 'i') + cmd.call(current_dir) == 1 ? true : false + else + Dir.pwd == '/' + end end def logaling_config_path