module Dir2svn
Constants
- ERR1
- ERR2
- ERR3
- VERSION
Public Class Methods
find_files(path, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 133 def find_files(path, exclude, do_puts) Dir2svn.find_paths(path, exclude, do_puts)[:files] end
find_folders(path, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 138 def find_folders(path, exclude, do_puts) Dir2svn.find_paths(path, exclude, do_puts)[:folders] end
find_paths(path, exclude, _do_puts)
click to toggle source
# File lib/dir2svn.rb, line 143 def find_paths(path, exclude, _do_puts) fls = [] fldrs = [] Find.find(path) do |p| if FileTest.directory?(p) if exclude.include?(File.basename(p)) Find.prune # Don't look any further into this directory. else fldrs << p next end else # ignore .folder files fls << p unless exclude.include?(File.basename(p)) end end { files: fls, folders: fldrs } end
sync_file_paths(src, dest, exclude, do_puts)
click to toggle source
See SvnRepository#sync_paths
# File lib/dir2svn.rb, line 63 def sync_file_paths(src, dest, exclude, do_puts) fls_dest = Dir2svn.find_files(dest, exclude, do_puts).collect { |p| p.sub(dest, '') } fls_src = Dir2svn.find_files(src, exclude, do_puts).collect { |p| p.sub(src, '') } fls_d = fls_dest - fls_src # deleted: in DEST but not (anymore) in SRC fls_a = fls_src - fls_dest # added: in SRC but not (yet) in SRC fls_f = fls_src - fls_a # found: in SRC and DEST: everything in SRC that we didn't add fls_u = [] # updated fls_e = [] # equal # Update files fls_f.collect do |p| # update files p1 = File.expand_path(p, src) # new version p0 = File.expand_path(p, dest) # existing version if File.identical?(p1, p0) fls_e << p else FileUtils.cp(p1, p0) fls_u << p end end # Add files fls_a.each do |p| p1 = File.expand_path(p, src) # new version p0 = File.expand_path(p, dest) unless File.exist?(File.dirname(p0)) # create parent dir of new file unless it exists # self.makedir_parents(File.dirname(p0)) unless File.exists?(File.dirname(p0)) cmd = "svn mkdir --parents \"#{File.dirname(p0)}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end FileUtils.cp(p1, p0) cmd = "svn add \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end # delete files fls_d.each do |p| p0 = File.expand_path(p, dest) cmd = "svn rm \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end { deleted: fls_d, added: fls_a, updated: fls_u, equal: fls_e } end
sync_folder_paths(src, dest, exclude, do_puts)
click to toggle source
See SvnRepository#sync_paths
# File lib/dir2svn.rb, line 112 def sync_folder_paths(src, dest, exclude, do_puts) fldrs_src = Dir2svn.find_folders(src, exclude, do_puts).collect { |p| p.sub(src, '') } fldrs_dest = Dir2svn.find_folders(dest, exclude, do_puts).collect { |p| p.sub(dest, '') } fldrs_d = (fldrs_dest - fldrs_src) # deleted folders: see deleted files fldrs_a = (fldrs_src - fldrs_dest) # add folders: see added files fldrs_d.each do |p| # deleted folders p0 = File.expand_path(p, dest) next unless File.exist?(p0) cmd = "svn rm \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end fldrs_a.each do |p| # added folders (must be empty, not very useful but..) p0 = File.expand_path(p, dest) cmd = "svn mkdir --parents \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end end
sync_paths(src, dest, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 50 def sync_paths(src, dest, exclude, do_puts) src = File.expand_path(src) + '/' dest = File.expand_path(dest) + '/' results = nil # First files, then folders, # as the processing of files can also sync folders results = Dir2svn.sync_file_paths(src, dest, exclude, do_puts) Dir2svn.sync_folder_paths(src, dest, exclude, do_puts) results end
Private Instance Methods
find_files(path, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 133 def find_files(path, exclude, do_puts) Dir2svn.find_paths(path, exclude, do_puts)[:files] end
find_folders(path, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 138 def find_folders(path, exclude, do_puts) Dir2svn.find_paths(path, exclude, do_puts)[:folders] end
find_paths(path, exclude, _do_puts)
click to toggle source
# File lib/dir2svn.rb, line 143 def find_paths(path, exclude, _do_puts) fls = [] fldrs = [] Find.find(path) do |p| if FileTest.directory?(p) if exclude.include?(File.basename(p)) Find.prune # Don't look any further into this directory. else fldrs << p next end else # ignore .folder files fls << p unless exclude.include?(File.basename(p)) end end { files: fls, folders: fldrs } end
sync_file_paths(src, dest, exclude, do_puts)
click to toggle source
See SvnRepository#sync_paths
# File lib/dir2svn.rb, line 63 def sync_file_paths(src, dest, exclude, do_puts) fls_dest = Dir2svn.find_files(dest, exclude, do_puts).collect { |p| p.sub(dest, '') } fls_src = Dir2svn.find_files(src, exclude, do_puts).collect { |p| p.sub(src, '') } fls_d = fls_dest - fls_src # deleted: in DEST but not (anymore) in SRC fls_a = fls_src - fls_dest # added: in SRC but not (yet) in SRC fls_f = fls_src - fls_a # found: in SRC and DEST: everything in SRC that we didn't add fls_u = [] # updated fls_e = [] # equal # Update files fls_f.collect do |p| # update files p1 = File.expand_path(p, src) # new version p0 = File.expand_path(p, dest) # existing version if File.identical?(p1, p0) fls_e << p else FileUtils.cp(p1, p0) fls_u << p end end # Add files fls_a.each do |p| p1 = File.expand_path(p, src) # new version p0 = File.expand_path(p, dest) unless File.exist?(File.dirname(p0)) # create parent dir of new file unless it exists # self.makedir_parents(File.dirname(p0)) unless File.exists?(File.dirname(p0)) cmd = "svn mkdir --parents \"#{File.dirname(p0)}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end FileUtils.cp(p1, p0) cmd = "svn add \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end # delete files fls_d.each do |p| p0 = File.expand_path(p, dest) cmd = "svn rm \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end { deleted: fls_d, added: fls_a, updated: fls_u, equal: fls_e } end
sync_folder_paths(src, dest, exclude, do_puts)
click to toggle source
See SvnRepository#sync_paths
# File lib/dir2svn.rb, line 112 def sync_folder_paths(src, dest, exclude, do_puts) fldrs_src = Dir2svn.find_folders(src, exclude, do_puts).collect { |p| p.sub(src, '') } fldrs_dest = Dir2svn.find_folders(dest, exclude, do_puts).collect { |p| p.sub(dest, '') } fldrs_d = (fldrs_dest - fldrs_src) # deleted folders: see deleted files fldrs_a = (fldrs_src - fldrs_dest) # add folders: see added files fldrs_d.each do |p| # deleted folders p0 = File.expand_path(p, dest) next unless File.exist?(p0) cmd = "svn rm \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end fldrs_a.each do |p| # added folders (must be empty, not very useful but..) p0 = File.expand_path(p, dest) cmd = "svn mkdir --parents \"#{p0}\"" out = `#{cmd}` puts "#{cmd}\n#{out}" if do_puts end end
sync_paths(src, dest, exclude, do_puts)
click to toggle source
# File lib/dir2svn.rb, line 50 def sync_paths(src, dest, exclude, do_puts) src = File.expand_path(src) + '/' dest = File.expand_path(dest) + '/' results = nil # First files, then folders, # as the processing of files can also sync folders results = Dir2svn.sync_file_paths(src, dest, exclude, do_puts) Dir2svn.sync_folder_paths(src, dest, exclude, do_puts) results end