private bool WatcherSyncUpdate(string remoteFolder, string localFolder, string localPath)
{
SleepWhileSuspended();
string localFilename = Path.GetFileName(localPath);
if (!Utils.WorthSyncing(Path.GetDirectoryName(localPath), localFilename, repoInfo))
{
return true;
}
try
{
// Get the remote directory, needed by the update method.
IFolder remoteBase = null;
if (File.Exists(localPath) || Directory.Exists(localPath))
{
bool isFolder = Utils.IsFolder(localPath);
SyncItem item = SyncItemFactory.CreateFromLocalPath(localPath, isFolder, repoInfo, database);
string remoteBaseName = CmisUtils.GetUpperFolderOfCmisPath(item.RemotePath);
remoteBase = (IFolder)session.GetObjectByPath(remoteBaseName);
if (null == remoteBase)
{
Logger.WarnFormat("The remote base folder {0} for local {1} does not exist, ignore for the update action", remoteBaseName, localPath);
return true; // Ignore is not a failure.
}
}
else
{
Logger.InfoFormat("The file/folder {0} is deleted, ignore for the update action", localPath);
return true;
}
// Update the item.
if (File.Exists(localPath))
{
// The item is a file.
bool success = false;
if (database.ContainsLocalFile(localPath))
{
if (database.LocalFileHasChanged(localPath))
{
success = UpdateFile(localPath, remoteBase);
Logger.InfoFormat("Update {0}: {1}", localPath, success);
}
else
{
success = true;
Logger.InfoFormat("File {0} remains unchanged, ignore for the update action", localPath);
}
}
else
{
success = UploadFile(localPath, remoteBase);
Logger.InfoFormat("Upload {0}: {1}", localPath, success);
}
if (success)
{
return true;
}
else
{
Logger.WarnFormat("Failure to update: {0}", localPath);
return false;
}
}
if (Directory.Exists(localPath))
{
// The item is a folder.
bool success = true;
if (database.ContainsFolder(localPath))
{
Logger.InfoFormat("Folder exists in Database {0}, ignore for the update action", localPath);
}
else
{
Logger.InfoFormat("Create locally created folder on server: {0}", localPath);
success &= UploadFolderRecursively(remoteBase, localPath);
}
return success;
}
Logger.InfoFormat("The file/folder {0} is deleted, ignore for the update action", localPath);
}
catch (Exception e)
{
ProcessRecoverableException("Could process watcher sync update: " + localPath, e);
return false;
}
return true;
}