Skip to content

Commit ac4ebd1

Browse files
committed
fix: Added the exception check in original code
1 parent cbdd8a6 commit ac4ebd1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ public override IDirectoryInfo GetParent(string path)
215215
/// <inheritdoc />
216216
public override void Move(string sourceDirName, string destDirName)
217217
{
218+
var fullSourcePath = Path.GetFullPath(sourceDirName);
219+
var fullDestPath = Path.GetFullPath(destDirName);
220+
221+
if (fullDestPath.Equals(fullDestPath))
222+
{
223+
throw new IOException("Source and destination path must be different.");
224+
}
225+
else if (Directory.Exists(fullDestPath) || File.Exists(fullDestPath))
226+
{
227+
throw new IOException("Destination path already exists.");
228+
}
218229
Directory.Move(sourceDirName, destDirName);
219230
}
220231

0 commit comments

Comments
 (0)