Browse Source

Merge pull request #20 from kborowinski/master

Don't throw error when 'Force' switch is specified
tags/4.2.4
Raimund Andrée [MSFT] 6 years ago
committed by GitHub
parent
commit
bb96a6bddb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions
  1. +2
    -2
      NTFSSecurity/ItemCmdlets/CopyItem2.cs
  2. +3
    -3
      NTFSSecurity/ItemCmdlets/MoveItem2.cs

+ 2
- 2
NTFSSecurity/ItemCmdlets/CopyItem2.cs View File

@@ -85,7 +85,7 @@ namespace NTFSSecurity
actualDestination = destination; actualDestination = destination;
} }


if (File.Exists(actualDestination))
if (!force & File.Exists(actualDestination))
{ {
WriteError(new ErrorRecord(new AlreadyExistsException(), "DestinationFileAlreadyExists", ErrorCategory.ResourceExists, actualDestination)); WriteError(new ErrorRecord(new AlreadyExistsException(), "DestinationFileAlreadyExists", ErrorCategory.ResourceExists, actualDestination));
return; return;
@@ -129,4 +129,4 @@ namespace NTFSSecurity
base.EndProcessing(); base.EndProcessing();
} }
} }
}
}

+ 3
- 3
NTFSSecurity/ItemCmdlets/MoveItem2.cs View File

@@ -85,7 +85,7 @@ namespace NTFSSecurity
actualDestination = destination; actualDestination = destination;
} }


if (File.Exists(actualDestination))
if (!force & File.Exists(actualDestination))
{ {
WriteError(new ErrorRecord(new AlreadyExistsException(), "DestinationFileAlreadyExists", ErrorCategory.ResourceExists, actualDestination)); WriteError(new ErrorRecord(new AlreadyExistsException(), "DestinationFileAlreadyExists", ErrorCategory.ResourceExists, actualDestination));
return; return;
@@ -97,7 +97,7 @@ namespace NTFSSecurity
{ {
if (ShouldProcess(resolvedPath, "Move File")) if (ShouldProcess(resolvedPath, "Move File"))
{ {
((FileInfo)item).MoveTo(actualDestination, MoveOptions.CopyAllowed, PathFormat.RelativePath);
((FileInfo)item).MoveTo(actualDestination, force ? MoveOptions.ReplaceExisting : MoveOptions.CopyAllowed, PathFormat.RelativePath);
WriteVerbose(string.Format("File '{0}' moved to '{0}'", resolvedPath, destination)); WriteVerbose(string.Format("File '{0}' moved to '{0}'", resolvedPath, destination));
} }
} }
@@ -105,7 +105,7 @@ namespace NTFSSecurity
{ {
if (ShouldProcess(resolvedPath, "Move Directory")) if (ShouldProcess(resolvedPath, "Move Directory"))
{ {
((DirectoryInfo)item).MoveTo(actualDestination, MoveOptions.CopyAllowed, PathFormat.RelativePath);
((DirectoryInfo)item).MoveTo(actualDestination, force ? MoveOptions.ReplaceExisting : MoveOptions.CopyAllowed, PathFormat.RelativePath);
WriteVerbose(string.Format("Directory '{0}' moved to '{0}'", resolvedPath, destination)); WriteVerbose(string.Format("Directory '{0}' moved to '{0}'", resolvedPath, destination));
} }
} }


Loading…
Cancel
Save