private bool RenameFile(string directory, string newFilename, IDocument remoteFile)
{
SleepWhileSuspended();
string oldPathname = Path.Combine(directory, remoteFile.Name);
string newPathname = Path.Combine(directory, newFilename);
try
{
Logger.InfoFormat("Renaming: {0} -> {1}", oldPathname, newPathname);
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = newFilename;
IDocument updatedDocument = (IDocument)remoteFile.UpdateProperties(properties);
// Update the path in the database...
database.MoveFile(SyncItemFactory.CreateFromLocalPath(oldPathname, false, repoInfo, database),
SyncItemFactory.CreateFromLocalPath(newPathname, false, repoInfo, database));
// Update timestamp in database.
database.SetFileServerSideModificationDate(
SyncItemFactory.CreateFromLocalPath(newPathname, false, repoInfo, database),
((DateTime)updatedDocument.LastModificationDate).ToUniversalTime());
Logger.InfoFormat("Renamed file: {0} -> {1}", oldPathname, newPathname);
return true;
}
catch (Exception e)
{
ProcessRecoverableException(String.Format("Could not rename file: {0} -> {1}", oldPathname, newPathname), e);
return false;
}
}