mergeEverBoxObject(oldOne, newOne);
//文件已经改变,遍历其Entries
List<EverBoxObject> oldEntries = oldOne.getEntries();
List<EverBoxObject> newEntries = newOne.getEntries();
oldIT : for (Iterator<EverBoxObject> oldIt = oldEntries.iterator(); oldIt.hasNext();) {
EverBoxObject oldEntry = oldIt.next();
for (Iterator<EverBoxObject> newIt = newEntries.iterator(); newIt.hasNext();) {
EverBoxObject newEntry = newIt.next();
if(oldEntry.getPath().equals(newEntry.getPath())) {
newIt.remove();
// System.out.println("找到一个已存在文件 " + oldEntry.getPath());
boolean flag = equals(oldEntry, newEntry);
if(flag) {
// System.out.println("没有做任何修改 "+oldEntry.getPath());
continue oldIT;
}
if(oldEntry.getType() == EverboxConfig.FILE && newEntry.getType() == EverboxConfig.FILE) {
mergeEverBoxObject(oldEntry, newEntry);
remoteModifyList.add(new EverboxModify(newEntry, EverboxModify.NEWER, true));
log.info("远程(服务器端)更新了一个文件 -- " + oldEntry.getPath());
continue oldIT;//TODO add into remote modify list
} else if(oldEntry.getType() != newEntry.getType()) {
// remoteModifyList.add(new EverboxModify(newEntry, EverboxModify.UPDATE, true));
// mergeEverBoxObject(oldEntry, newEntry);
log.info("远程(服务器端) !警告!! 文件类型(文件夹<-->文件)改变!! -- " + oldEntry.getPath());
// continue oldIT;//TODO add into remote modify list
}
JSONObject obj = new JSONObject();
obj.put("path", newEntry.getPath());
StringBuilder sb = new StringBuilder();
FS.get(obj, sb);
newEntry = Json.fromJson(EverBoxObject.class, sb.toString());
reflashRemote(oldEntry, newEntry);
continue oldIT;
}
}
//No match in newOne? Object shall be deleted!!
oldIt.remove();//TODO add into remote modify list
remoteModifyList.add(new EverboxModify(oldEntry, EverboxModify.MISS, true));
log.info("远程(服务器端)删除了一个文件 -- " + oldEntry.getPath());
}
//仍然有新的Entry? 那就是远程新增咯
if(newEntries.size() > 0) {
for (EverBoxObject newEntry : newEntries) {
System.out.println(newEntry.getPath());
oldEntries.add(listRemote(newEntry));//TODO add into remote modify list
List<EverBoxObject> list = new ArrayList<EverBoxObject>();
newEntry.asList(list);
for (EverBoxObject ebo : list) {
remoteModifyList.add(new EverboxModify(ebo, EverboxModify.ADD, true));
log.info("远程(服务器端)新增了一个文件 -- " + ebo.getPath());
}
}