Sha256: ac3c98395ab17be58cff0d9ae0a73e768c0d6a6be0d158bf4f5ab95e87ea2a49
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
# -*- coding: utf-8 -*- module TreeRb class SqliteDirTreeVisitor < BasicTreeNodeVisitor def initialize(filename) @db = SQLite3::Database.new(filename) @db.execute("create table files(path varchar(1024), size integer, digest varchar(40))") end def visit_leaf(pathname) puts pathname stat = File.lstat(pathname) digest = SHA1.file(pathname).hexdigest @db.execute("insert into files (path, size, digest) values ( \"#{pathname}\", \"#{stat.size}\", \"#{digest}\")") # entry = Entry.from_filename(filename) # me.add_entry(entry) # bytes += entry.size # if me.verbose_level > 0 # print "#{CR}#{filename}#{CLEAR}" # end # if me.show_progress # sec = Time.now - start # print "#{CR}bytes: #{bytes.to_human} time: #{sec} bytes/sec #{bytes/sec} #{CLEAR}" # end #content = ContentFile.new(pathname, @options) # connect the leaf_node created to the last tree_node on the stack #@nr_files += 1 #LeafNode.new(content, @stack.last) end def find_duplicates # Loop through digests. @db.execute("select digest,count(1) as count from files group by digest order by count desc").each do |row| if row[1] > 1 # Skip unique files. puts "Duplicates found:" digest = row[0] # List the duplicate files. db.execute("select digest,path from files where digest='#{digest}'").each do |dup_row| puts "[#{digest}] #{dup_row[1]}" end end end end end end # end module TreeVisitor
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tree.rb-0.3.7 | lib/tree_rb/visitors/sqlite_dir_tree_visitor.rb |
tree.rb-0.3.6 | lib/tree_rb/visitors/sqlite_dir_tree_visitor.rb |