Revision f6ca240a trunk/Pithos.Core/Agents/NetworkAgent.cs
b/trunk/Pithos.Core/Agents/NetworkAgent.cs | ||
---|---|---|
240 | 240 |
var downloadPath=action.LocalFile.GetProperCapitalization(); |
241 | 241 |
|
242 | 242 |
var cloudHash = cloudFile.Hash.ToLower(); |
243 |
string previousCloudHash = cloudFile.PreviousHash.ToLower(); |
|
243 | 244 |
var localHash = action.LocalHash.Value.ToLower(); |
244 | 245 |
var topHash = action.TopHash.Value.ToLower(); |
245 | 246 |
|
246 |
//Not enough to compare only the local hashes, also have to compare the tophashes |
|
247 |
//At this point we know that an object has changed on the server and that a local |
|
248 |
//file already exists. We need to decide whether the file has only changed on |
|
249 |
//the server or there is a conflicting change on the client. |
|
250 |
// |
|
247 | 251 |
|
252 |
//Not enough to compare only the local hashes (MD5), also have to compare the tophashes |
|
248 | 253 |
//If any of the hashes match, we are done |
249 | 254 |
if ((cloudHash == localHash || cloudHash == topHash)) |
250 | 255 |
{ |
... | ... | |
253 | 258 |
} |
254 | 259 |
|
255 | 260 |
//The hashes DON'T match. We need to sync |
256 |
var lastLocalTime = localFile.LastWriteTime; |
|
257 |
var lastUpTime = cloudFile.Last_Modified; |
|
258 |
|
|
259 |
//If the local file is newer upload it |
|
260 |
if (lastUpTime <= lastLocalTime) |
|
261 |
|
|
262 |
// If the previous tophash matches the local tophash, the file was only changed on the server. |
|
263 |
if (localHash == previousCloudHash) |
|
261 | 264 |
{ |
262 |
//It probably means it was changed while the app was down |
|
263 |
UploadCloudFile(action); |
|
265 |
await DownloadCloudFile(accountInfo, cloudFile, downloadPath); |
|
264 | 266 |
} |
265 | 267 |
else |
266 | 268 |
{ |
267 |
//It the cloud file has a later date, it was modified by another user or computer. |
|
268 |
//We need to check the local file's status |
|
269 |
var status = StatusKeeper.GetFileStatus(downloadPath); |
|
270 |
switch (status) |
|
271 |
{ |
|
272 |
case FileStatus.Unchanged: |
|
273 |
//If the local file's status is Unchanged, we can go on and download the newer cloud file |
|
274 |
await DownloadCloudFile(accountInfo,cloudFile,downloadPath); |
|
275 |
break; |
|
276 |
case FileStatus.Modified: |
|
277 |
//If the local file is Modified, we may have a conflict. In this case we should mark the file as Conflict |
|
278 |
//We can't ensure that a file modified online since the last time will appear as Modified, unless we |
|
279 |
//index all files before we start listening. |
|
280 |
case FileStatus.Created: |
|
281 |
//If the local file is Created, it means that the local and cloud files aren't related, |
|
282 |
// yet they have the same name. |
|
283 |
|
|
284 |
//In both cases we must mark the file as in conflict |
|
285 |
ReportConflict(downloadPath); |
|
286 |
break; |
|
287 |
default: |
|
288 |
//Other cases should never occur. Mark them as Conflict as well but log a warning |
|
289 |
ReportConflict(downloadPath); |
|
290 |
Log.WarnFormat("Unexcepted status {0} for file {1}->{2}", status, |
|
291 |
downloadPath, action.CloudFile.Name); |
|
292 |
break; |
|
293 |
} |
|
269 |
//If the previous and local hash don't match, there was a local conflict |
|
270 |
//that was not uploaded to the server. We have a conflict |
|
271 |
ReportConflict(downloadPath); |
|
294 | 272 |
} |
295 | 273 |
} |
296 | 274 |
|
Also available in: Unified diff