lib/bdsync/core.rb in bdsync-2.1.2 vs lib/bdsync/core.rb in bdsync-2.2.0

- old
+ new

@@ -171,12 +171,16 @@ elsif File.directory? local_path handle_local_conflict local_path download_file local_path, remote_path update_file_data relative_path, local_path, remote.mtime else - handle_local_conflict local_path - download_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_local_conflict local_path + download_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime end when :directory if !File.exist? local_path local_mkdir local_path @@ -200,12 +204,16 @@ elsif remote.directory? handle_remote_conflict remote_path remote = upload_file local_path, remote_path update_file_data relative_path, local_path, remote.mtime else - handle_remote_conflict remote_path - remote = upload_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_remote_conflict remote_path + remote = upload_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime end when :directory if !remote remote = remote_mkdir remote_path @@ -258,16 +266,24 @@ elsif !local_changed && remote_changed download_file local_path, remote_path update_file_data relative_path, local_path, remote.mtime else if File.mtime(local_path).to_i > remote.mtime - handle_remote_conflict remote_path - remote = upload_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_remote_conflict remote_path + remote = upload_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime else - handle_local_conflict local_path - download_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_local_conflict local_path + download_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime end end end when :directory @@ -337,16 +353,24 @@ elsif !local_changed && remote_changed download_file local_path, remote_path update_file_data relative_path, local_path, remote.mtime else if File.mtime(local_path).to_i > remote.mtime - handle_remote_conflict remote_path - remote = upload_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_remote_conflict remote_path + remote = upload_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime else - handle_local_conflict local_path - download_file local_path, remote_path + # compare file contents, conflict if not equal + if !is_same_contents local_path, remote_path + handle_local_conflict local_path + download_file local_path, remote_path + end + update_file_data relative_path, local_path, remote.mtime end end end when :directory @@ -434,8 +458,14 @@ FileUtils.mkdir_p path if !File.directory? path end def local_ensure_parent path local_ensure_dir File.dirname path + end + + def is_same_contents local_path, remote_path + local_file_md5 = Utils.file_md5 local_path + remote_file_md5 = get_remote_file_md5 remote_path + local_file_md5 == remote_file_md5 end end end