if (String.Equals(tuple.FilePath ,serverPath,StringComparison.InvariantCultureIgnoreCase)) \r
return serverPath;\r
\r
- if (tuple.FileInfo.Exists)\r
+ tuple.FileInfo.Refresh();\r
+ //The file/folder may not exist if it was moved because its parent moved\r
+ if (!tuple.FileInfo.Exists)\r
{\r
- using (StatusNotification.GetNotifier("Moving local {0}", "Moved local {0}", Path.GetFileName(tuple.FilePath)))\r
- using(NetworkGate.Acquire(tuple.FilePath,NetworkOperation.Renaming))\r
+ var target=FileInfoExtensions.FromPath(serverPath);\r
+ if (!target.Exists)\r
{\r
- var fi = tuple.FileInfo as FileInfo;\r
- if (fi != null)\r
- fi.MoveTo(serverPath);\r
- var di = tuple.FileInfo as DirectoryInfo;\r
- if (di != null)\r
- di.MoveTo(serverPath);\r
+ Log.ErrorFormat("No source or target found while trying to move {0} to {1}", tuple.FileInfo.FullName, serverPath);\r
}\r
- StatusKeeper.StoreInfo(serverPath, tuple.ObjectInfo);\r
+ return serverPath;\r
}\r
- else\r
+\r
+ using (StatusNotification.GetNotifier("Moving local {0}", "Moved local {0}", Path.GetFileName(tuple.FilePath)))\r
+ using(NetworkGate.Acquire(tuple.FilePath,NetworkOperation.Renaming))\r
{\r
- Debug.Assert(false, "File does not exist");\r
+ \r
+ var fi = tuple.FileInfo as FileInfo;\r
+ if (fi != null)\r
+ {\r
+ var targetFile = new FileInfo(serverPath);\r
+ if (!targetFile.Directory.Exists)\r
+ targetFile.Directory.Create();\r
+ fi.MoveTo(serverPath);\r
+ }\r
+ var di = tuple.FileInfo as DirectoryInfo;\r
+ if (di != null)\r
+ {\r
+ var targetDir = new DirectoryInfo(serverPath);\r
+ if (!targetDir.Parent.Exists)\r
+ targetDir.Parent.Create();\r
+ di.MoveTo(serverPath);\r
+ }\r
}\r
+ StatusKeeper.StoreInfo(serverPath, tuple.ObjectInfo);\r
+\r
return serverPath;\r
}\r
\r