protected override async Task OnMoveFileAsync(FilePath localSrcPath, FilePath localDestPath, bool force, ProgressMonitor monitor) { bool destIsVersioned = false; if (File.Exists(localDestPath)) { if (string.Equals(localSrcPath, localDestPath, StringComparison.OrdinalIgnoreCase)) { Svn.Move(localSrcPath, localDestPath, true, monitor); return; } throw new InvalidOperationException("Cannot move file. Destination file already exist."); } if (await IsVersionedAsync(localDestPath, monitor.CancellationToken)) { // Revert to the original status await RevertAsync(localDestPath, false, monitor); if (File.Exists(localDestPath)) { File.Delete(localDestPath); } destIsVersioned = true; } VersionInfo srcInfo = await GetVersionInfoAsync(localSrcPath, VersionInfoQueryFlags.IgnoreCache); if (srcInfo != null && srcInfo.HasLocalChange(VersionStatus.ScheduledAdd)) { // Subversion automatically detects the rename and moves the new file accordingly. if (!destIsVersioned) { MakeDirVersioned(Path.GetDirectoryName(localDestPath), monitor); Svn.Move(localSrcPath, localDestPath, force, monitor); } else { await base.OnMoveFileAsync(localSrcPath, localDestPath, force, monitor); Add(localDestPath, false, monitor); await DeleteFileAsync(localSrcPath, force, monitor, keepLocal : false); } } else { if (!destIsVersioned && await IsVersionedAsync(localSrcPath, monitor.CancellationToken)) { MakeDirVersioned(Path.GetDirectoryName(localDestPath), monitor); Svn.Move(localSrcPath, localDestPath, force, monitor); } else { await base.OnMoveFileAsync(localSrcPath, localDestPath, force, monitor); } } ClearCachedVersionInfo(localSrcPath, localDestPath); }
protected override void OnMoveFile(FilePath localSrcPath, FilePath localDestPath, bool force, IProgressMonitor monitor) { bool destIsVersioned = false; if (File.Exists(localDestPath)) { throw new InvalidOperationException("Cannot move file. Destination file already exist."); } if (IsVersioned(localDestPath)) { // Revert to the original status Revert(localDestPath, false, monitor); if (File.Exists(localDestPath)) { File.Delete(localDestPath); } destIsVersioned = true; } VersionInfo srcInfo = GetVersionInfo(localSrcPath, VersionInfoQueryFlags.IgnoreCache); if (srcInfo != null && srcInfo.HasLocalChange(VersionStatus.ScheduledAdd)) { // Subversion automatically detects the rename and moves the new file accordingly. if (!destIsVersioned) { MakeDirVersioned(Path.GetDirectoryName(localDestPath), monitor); Svn.Move(localSrcPath, localDestPath, force, monitor); } else { base.OnMoveFile(localSrcPath, localDestPath, force, monitor); if (!destIsVersioned) { Add(localDestPath, false, monitor); } } } else { if (!destIsVersioned && IsVersioned(localSrcPath)) { MakeDirVersioned(Path.GetDirectoryName(localDestPath), monitor); Svn.Move(localSrcPath, localDestPath, force, monitor); } else { base.OnMoveFile(localSrcPath, localDestPath, force, monitor); } } }
public override void MoveFile(FilePath srcPath, FilePath destPath, bool force, IProgressMonitor monitor) { bool destIsVersioned = false; if (File.Exists(destPath)) { throw new InvalidOperationException("Cannot move file. Destination file already exist."); } if (IsVersioned(destPath)) { // Revert to the original status Revert(destPath, false, monitor); if (File.Exists(destPath)) { File.Delete(destPath); } destIsVersioned = true; } VersionInfo srcInfo = GetVersionInfo(srcPath, false); if (srcInfo != null && srcInfo.HasLocalChange(VersionStatus.ScheduledAdd)) { // If the file is scheduled to add, cancel it, move the file, and schedule to add again Revert(srcPath, false, monitor); if (!destIsVersioned) { MakeDirVersioned(Path.GetDirectoryName(destPath), monitor); } base.MoveFile(srcPath, destPath, force, monitor); if (!destIsVersioned) { Add(destPath, false, monitor); } } else { if (!destIsVersioned && IsVersioned(srcPath)) { MakeDirVersioned(Path.GetDirectoryName(destPath), monitor); Svn.Move(srcPath, destPath, force, monitor); } else { base.MoveFile(srcPath, destPath, force, monitor); } } }
public override void MoveDirectory(FilePath srcPath, FilePath destPath, bool force, IProgressMonitor monitor) { if (IsVersioned(destPath)) { VersionInfo vinfo = GetVersionInfo(destPath, false); if (!vinfo.HasLocalChange(VersionStatus.ScheduledDelete) && Directory.Exists(destPath)) { throw new InvalidOperationException("Cannot move directory. Destination directory already exist."); } srcPath = srcPath.FullPath; // The target directory does not exist, but it is versioned. It may be because // it is scheduled to delete, or maybe it has been physicaly deleted. In any // case we are going to replace the old directory by the new directory. // Revert the old directory, so we can see which files were there so // we can delete or replace them Revert(destPath, true, monitor); // Get the list of files in the directory to be replaced ArrayList oldFiles = new ArrayList(); GetDirectoryFiles(destPath, oldFiles); // Get the list of files to move ArrayList newFiles = new ArrayList(); GetDirectoryFiles(srcPath, newFiles); // Move all new files to the new destination Hashtable copiedFiles = new Hashtable(); Hashtable copiedFolders = new Hashtable(); foreach (string file in newFiles) { string src = Path.GetFullPath(file); string dst = Path.Combine(destPath, src.Substring(((string)srcPath).Length + 1)); if (File.Exists(dst)) { File.Delete(dst); } // Make sure the target directory exists string destDir = Path.GetDirectoryName(dst); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } // If the source file is versioned, make sure the target directory // is also versioned. if (IsVersioned(src)) { MakeDirVersioned(destDir, monitor); } MoveFile(src, dst, true, monitor); copiedFiles [dst] = dst; string df = Path.GetDirectoryName(dst); copiedFolders [df] = df; } // Delete all old files which have not been replaced ArrayList foldersToDelete = new ArrayList(); foreach (string oldFile in oldFiles) { if (!copiedFiles.Contains(oldFile)) { DeleteFile(oldFile, true, monitor); string fd = Path.GetDirectoryName(oldFile); if (!copiedFolders.Contains(fd) && !foldersToDelete.Contains(fd)) { foldersToDelete.Add(fd); } } } // Delete old folders foreach (string folder in foldersToDelete) { Svn.Delete(folder, true, monitor); } // Delete the source directory DeleteDirectory(srcPath, true, monitor); } else { if (Directory.Exists(destPath)) { throw new InvalidOperationException("Cannot move directory. Destination directory already exist."); } VersionInfo srcInfo = GetVersionInfo(srcPath, false); if (srcInfo != null && srcInfo.HasLocalChange(VersionStatus.ScheduledAdd)) { // If the directory is scheduled to add, cancel it, move the directory, and schedule to add it again MakeDirVersioned(Path.GetDirectoryName(destPath), monitor); Revert(srcPath, true, monitor); base.MoveDirectory(srcPath, destPath, force, monitor); Add(destPath, true, monitor); } else { if (IsVersioned(srcPath)) { MakeDirVersioned(Path.GetDirectoryName(destPath), monitor); Svn.Move(srcPath, destPath, force, monitor); } else { base.MoveDirectory(srcPath, destPath, force, monitor); } } } }