Skip to content

Commit

Permalink
Fix path_to_id issue where last shorty was stripped
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Jun 9, 2011
1 parent b449346 commit 0ab346d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/pairtree/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.id_to_path id

def self.path_to_id ppath
parts = ppath.split(File::SEPARATOR)
parts.pop if @@leaf_proc
parts.pop if @@leaf_proc and parts.last.length > Root::SHORTY_LENGTH
Pairtree::Identifier.decode(parts.join)
end

Expand Down
14 changes: 5 additions & 9 deletions lib/pairtree/root.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'find'
require 'fileutils'
module Pairtree
class Root
Expand All @@ -19,15 +18,12 @@ def list
return [] unless pairtree_root? @root

Dir.chdir(@root) do
Find.find(*Dir.entries('.').reject { |x| x =~ /^\./ }) do |path|
if File.directory? path
Find.prune if File.basename(path).length > @shorty_length
objects << path if Dir.entries(path).any? { |f| f.length > @shorty_length or File.file? File.join(path, f) }
next
end
end
possibles = Dir['**/?'] + Dir['**/??']
possibles.each { |path|
contents = Dir.entries(path).reject { |x| x =~ /^\./ }
objects << path unless contents.all? { |f| f.length <= @shorty_length and File.directory?(File.join(path, f)) }
}
end

objects.map { |x| @prefix + Pairtree::Path.path_to_id(x) }
end

Expand Down

0 comments on commit 0ab346d

Please sign in to comment.