|
|
|
@ -1,14 +1,15 @@
|
|
|
|
|
onmessage = function (e) {
|
|
|
|
|
var request = e.data;
|
|
|
|
|
|
|
|
|
|
var delete_list = [];
|
|
|
|
|
var update_list = [];
|
|
|
|
|
var result_files = {};
|
|
|
|
|
result_files.delete_list = [];
|
|
|
|
|
result_files.update_list = [];
|
|
|
|
|
|
|
|
|
|
switch (request.command) {
|
|
|
|
|
case 'compare':
|
|
|
|
|
compare_file_info(request.local_file_info, request.remote_file_info, delete_list, update_list);
|
|
|
|
|
send_command('delete', delete_list);
|
|
|
|
|
send_command('update', update_list);
|
|
|
|
|
compare_file_info(request.local_file_info, request.remote_file_info, result_files);
|
|
|
|
|
send_command('delete', result_files.delete_list);
|
|
|
|
|
send_command('update', result_files.update_list);
|
|
|
|
|
send_command('finish', []);
|
|
|
|
|
break;
|
|
|
|
|
case 'finish':
|
|
|
|
@ -17,28 +18,28 @@ onmessage = function (e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function compare_file_info(local_file_info, remote_file_info, delete_list, update_list) {
|
|
|
|
|
function compare_file_info(local_file_info, remote_file_info, result_files) {
|
|
|
|
|
if (!remote_file_info) {
|
|
|
|
|
delete_list = delete_list.concat(generate_file_list(local_file_info));
|
|
|
|
|
result_files.delete_list = result_files.delete_list.concat(generate_file_list(local_file_info));
|
|
|
|
|
} else if (!local_file_info) {
|
|
|
|
|
update_list = update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
result_files.update_list = result_files.update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
} else if (local_file_info.is_dir !== remote_file_info.is_dir) {
|
|
|
|
|
delete_list = delete_list.concat(generate_file_list(local_file_info));
|
|
|
|
|
update_list = update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
result_files.delete_list = result_files.delete_list.concat(generate_file_list(local_file_info));
|
|
|
|
|
result_files.update_list = result_files.update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
} else if (local_file_info.sha_512 !== remote_file_info.sha_512) {
|
|
|
|
|
if (local_file_info.is_dir) {
|
|
|
|
|
var visited_children = new Set();
|
|
|
|
|
for (var i in local_file_info.children) {
|
|
|
|
|
compare_file_info(local_file_info.children[i], remote_file_info.children[i], delete_list, update_list);
|
|
|
|
|
compare_file_info(local_file_info.children[i], remote_file_info.children[i], result_files);
|
|
|
|
|
visited_children.add(i);
|
|
|
|
|
}
|
|
|
|
|
for (var i in remote_file_info.children) {
|
|
|
|
|
if (!visited_children.has(i)) {
|
|
|
|
|
update_list = update_list.concat(generate_file_list(remote_file_info.children[i]));
|
|
|
|
|
result_files.update_list = result_files.update_list.concat(generate_file_list(remote_file_info.children[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
update_list = update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
result_files.update_list = result_files.update_list.concat(generate_file_list(remote_file_info));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|