From 98275f4864e9224e5c9054927299a3a6277d2b4a Mon Sep 17 00:00:00 2001 From: kou1okada Date: Fri, 14 Feb 2014 00:15:36 +0900 Subject: [PATCH 1/2] Fixed FSSM::Pathname.segments method to work correctly. Maybe, this problem occurs only under the cygwin environment. The FSSM::Pathname.segments method did not work correctly. Therefore reconnection with join method failed to insert File::SEPARA This problem makes failure for watch sub-command of compass (http://compass-style.org/). before: FSSM::Pathname.for("/tmp/foo").segments # => ["//", "tmp", "foo"] FSSM::Pathname.for("/tmp/foo").join("bar") # => # # OK, no problem. But a result of segments is a little bit strange. FSSM::Pathname.for("//host/share/foo").segments # => ["//", "host", "share", "foo"] FSSM::Pathname.for("//host/share/foo").join("bar") # => # # OK, no problem. But a result of segments is a little bit strange. cache = FSSM::Tree::Cache.new # => # cache.set "/tmp/foo" # => 2014-02-13 23:20:19 +0900 cache.files # => {"//tmpfoo"=>2014-02-13 23:20:19 +0900} # Oops!!! The path is corrupted. It's a problem!!! after: FSSM::Pathname.for("/tmp/foo").segments # => ["/", "tmp", "foo"] FSSM::Pathname.for("/tmp/foo").join("bar") # => # # OK, no problem. A result of segments is also reasonable. FSSM::Pathname.for("//host/share/foo").segments # => ["//host/share", "foo"] FSSM::Pathname.for("//host/share/foo").join("bar") # => # # OK, no problem. A result of segments is also reasonable. cache = FSSM::Tree::Cache.new # => # cache.set "/tmp/foo" # => 2014-02-13 23:20:19 +0900 cache.files # => {"/tmp/foo"=>2014-02-13 23:20:19 +0900} # OK, fixed a problem. --- lib/fssm/pathname.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fssm/pathname.rb b/lib/fssm/pathname.rb index ad174d4..fee0116 100644 --- a/lib/fssm/pathname.rb +++ b/lib/fssm/pathname.rb @@ -20,10 +20,12 @@ def is_virtual? def segments path = to_s - array = path.split(File::SEPARATOR) - array.delete('') - array.insert(0, File::SEPARATOR) if path[0, 1] == File::SEPARATOR - array[0] += File::SEPARATOR if path[0, 3] =~ SEPARATOR_PAT + array = [] + while !Pathname.new(path).root? && !path.empty? + array.unshift File.basename(path) + path = File.dirname(path) + end + array.unshift path unless path.empty? array end From a07755703a81a766481fe4d3d6b30c658914a4c9 Mon Sep 17 00:00:00 2001 From: kou1okada Date: Tue, 25 Feb 2014 12:23:02 +0900 Subject: [PATCH 2/2] Bugfix for FSSM::Tree::Cache on UNC. Maybe, this problem occurs only under the cygwin environment. Cause of a problem: Pathname("//host/share").join("hoge.txt") # => # Pathname("//host/share/").join("hoge.txt") # => # This makes corruption at FSSM::Pathname.for().join() in FSSM::Tree::NodeEnumerable.each(). Therefore FSSM::Tree::Cache.files is not work correctly on UNC. This patch modifies the behavior as below. before: FSSM::Pathname.for("//host/share/hoge.txt").segments # => ["//host/share", "hoge.txt"] cache = FSSM::Tree::Cache.new # => # cache.set "//host/share/hoge.txt" # => 2014-02-25 11:38:19 +0900 cache.files # => {"//host/sharehoge.txt"=>2014-02-25 11:38:19 +0900} after: FSSM::Pathname.for("//host/share/hoge.txt").segments # => ["//host/share/", "hoge.txt"] cache = FSSM::Tree::Cache.new # => # cache.set "//host/share/hoge.txt" # => 2014-02-25 11:38:19 +0900 cache.files # => {"//host/share/hoge.txt"=>2014-02-25 11:38:19 +0900} --- lib/fssm/pathname.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fssm/pathname.rb b/lib/fssm/pathname.rb index fee0116..13265cd 100644 --- a/lib/fssm/pathname.rb +++ b/lib/fssm/pathname.rb @@ -21,11 +21,13 @@ def is_virtual? def segments path = to_s array = [] - while !Pathname.new(path).root? && !path.empty? + curdir = File.dirname("") + while !Pathname.new(path).root? && !(path.empty? || path == curdir) array.unshift File.basename(path) path = File.dirname(path) end - array.unshift path unless path.empty? + suffix = path[-1] =~ Pathname::SEPARATOR_PAT ? "" : File::SEPARATOR + array.unshift "#{path}#{suffix}" unless path.empty? || path == curdir array end