Browse Source

fix #418: File rename can break project file. The SVN AddIn should check if the rename operation is legal before attempting to rename a file.

pull/499/head
Siegfried Pammer 11 years ago
parent
commit
11662db1b9
  1. 4
      src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs
  2. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 49
      src/Main/Base/Project/Workbench/File/FileHelpers.cs
  4. 36
      src/Main/SharpDevelop/Workbench/FileService.cs

4
src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs

@ -389,6 +389,10 @@ namespace ICSharpCode.Svn.Commands @@ -389,6 +389,10 @@ namespace ICSharpCode.Svn.Commands
if (!AddInOptions.AutomaticallyRenameFiles) return;
string fullSource = Path.GetFullPath(e.SourceFile);
if (!CanBeVersionControlledFile(fullSource)) return;
if (!FileHelpers.CheckRenameOrReplacePossible(e)) {
e.Cancel = true;
return;
}
try {
using (SvnClientWrapper client = new SvnClientWrapper()) {
SvnMessageView.HandleNotifications(client);

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -366,6 +366,7 @@ @@ -366,6 +366,7 @@
<Compile Include="Workbench\DisplayBinding\ISecondaryDisplayBinding.cs" />
<Compile Include="Workbench\FakeXmlViewContent.cs" />
<Compile Include="Workbench\FileChangeWatcher.cs" />
<Compile Include="Workbench\File\FileHelpers.cs" />
<Compile Include="Workbench\File\FileService.cs" />
<Compile Include="Workbench\File\IRecentOpen.cs" />
<Compile Include="Workbench\ICustomizedCommands.cs" />

49
src/Main/Base/Project/Workbench/File/FileHelpers.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Workbench
{
/// <summary>
/// Utility/helper methods for IFileService to avoid changing the IFileService interface.
/// </summary>
public static class FileHelpers
{
/// <summary>
/// Checks that the rename/overwrite operation is possible.
/// </summary>
public static bool CheckRenameOrReplacePossible(FileRenameEventArgs e, bool replaceAllowed = false)
{
if (e.IsDirectory && Directory.Exists(e.SourceFile)) {
if (!replaceAllowed && Directory.Exists(e.TargetFile)) {
SD.MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
} else if (File.Exists(e.SourceFile)) {
if (!replaceAllowed && File.Exists(e.TargetFile)) {
SD.MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
}
return true;
}
}
}

36
src/Main/SharpDevelop/Workbench/FileService.cs

@ -580,20 +580,12 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -580,20 +580,12 @@ namespace ICSharpCode.SharpDevelop.Workbench
return false;
if (!eargs.OperationAlreadyDone) {
try {
if (isDirectory && Directory.Exists(oldName)) {
if (Directory.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
if (FileHelpers.CheckRenameOrReplacePossible(eargs)) {
if (isDirectory) {
Directory.Move(oldName, newName);
} else {
File.Move(oldName, newName);
}
Directory.Move(oldName, newName);
} else if (File.Exists(oldName)) {
if (File.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
File.Move(oldName, newName);
}
} catch (Exception e) {
if (isDirectory) {
@ -624,20 +616,12 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -624,20 +616,12 @@ namespace ICSharpCode.SharpDevelop.Workbench
return false;
if (!eargs.OperationAlreadyDone) {
try {
if (isDirectory && Directory.Exists(oldName)) {
if (!overwrite && Directory.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
FileUtility.DeepCopy(oldName, newName, overwrite);
} else if (File.Exists(oldName)) {
if (!overwrite && File.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
if (FileHelpers.CheckRenameOrReplacePossible(eargs, overwrite)) {
if (isDirectory) {
FileUtility.DeepCopy(oldName, newName, overwrite);
} else {
File.Copy(oldName, newName, overwrite);
}
File.Copy(oldName, newName, overwrite);
}
} catch (Exception e) {
if (isDirectory) {

Loading…
Cancel
Save