diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-04 13:40:42 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-14 12:48:15 +0100 |
commit | f948c00757ca9529817c7368610b0c0d6734d48f (patch) | |
tree | b163f8e0c65fd2405efc92bab5da9926241f88b6 /lib | |
parent | a7f99b67a0bf1160f41ebf4dc92c618eb13a7a10 (diff) | |
download | gitlab-ce-f948c00757ca9529817c7368610b0c0d6734d48f.tar.gz |
Do not depend on universe when checking parent in `StringPath`
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/string_path.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb index 9948502e8ea..4d024b3ff73 100644 --- a/lib/gitlab/string_path.rb +++ b/lib/gitlab/string_path.rb @@ -7,6 +7,7 @@ module Gitlab # class StringPath attr_reader :path, :universe + attr_accessor :name def initialize(path, universe, metadata = []) @path = sanitize(path) @@ -35,7 +36,7 @@ module Gitlab end def has_parent? - @universe.include?(@path.sub(basename, '')) + nodes > 1 end def parent @@ -48,7 +49,7 @@ module Gitlab end def name - @path.split(::File::SEPARATOR).last + @name || @path.split(::File::SEPARATOR).last end def has_descendants? @@ -75,7 +76,11 @@ module Gitlab end def directories! - @path =~ %r{^\./[^/]/} ? directories.prepend(parent) : directories + return directories unless has_parent? && directory? + + dotted_parent = parent + dotted_parent.name = '..' + directories.prepend(dotted_parent) end def files @@ -88,6 +93,10 @@ module Gitlab @metadata[index] end + def nodes + @path.count('/') + (file? ? 1 : 0) + end + def ==(other) @path == other.path && @universe == other.universe end |