Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectoryInfo.MoveTo does not update the object's Name property #27911

Closed
alexischr opened this issue Nov 14, 2018 · 2 comments
Closed

DirectoryInfo.MoveTo does not update the object's Name property #27911

alexischr opened this issue Nov 14, 2018 · 2 comments
Milestone

Comments

@alexischr
Copy link
Contributor

The following program prints DIT.MoveToUpdateProperties.Test (the original Name) on CoreFX, and DIT.MoveToUpdateProperties3.Test (the final Name) on .NET Framework and Mono:

using System;
using System.IO;

namespace MoveTo_UpdateProperties
{
	class Program
	{
		static void Main(string[] args)
		{
			string TempFolder = Path.GetTempPath();
			char DSC = Path.DirectorySeparatorChar;
			string path = TempFolder + DSC + "DIT.MoveToUpdateProperties.Test";
			string path2 = TempFolder + DSC + "DIT.MoveToUpdateProperties2.Test";
			string path3 = path2 + DSC + "DIT.MoveToUpdateProperties3.Test";
			if (Directory.Exists (path2))
				Directory.Delete (path2);
			if (Directory.Exists (path))
				Directory.Delete (path);
			Directory.CreateDirectory (path);
			Directory.CreateDirectory (path2);

			DirectoryInfo info = new DirectoryInfo(path);
			info.MoveTo (path3);
			Console.WriteLine (info.Name);
		}
	}
}

The issue in the code is here (_name is not updated): https://github.com/dotnet/corefx/blob/8bd31a2a571923d3eb86dc728c272d0b6093a4d2/src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs#L228

Using fileName: null instead fixes the issue.

@danmoseley
Copy link
Member

Thanks @alexischr - do you plan to offer a PR?

@alexischr
Copy link
Contributor Author

Will do, just wanted to get an okay on the fix :)

alexischr referenced this issue in mono/corefx Nov 15, 2018
Re-initialize DirectoryInfo.Name after a MoveTo() operation
marek-safar referenced this issue in mono/mono Dec 7, 2018
Includes the following from System.IO:

* FileSystemInfo
* FileInfo
* DirectoryInfo
* Directory
* FileSystem
* Path `Join()` Span API

and all of System.IO.Enumeration namespace.

Adds about 1600 System.IO tests

Behavior changes:
* `File.Replace` now replaces files even if they are read-only (using the `rename` syscall on Unix)
* Directory enumeration is no longer stable in the way that many Mono tests expect
* Some changes in when/whether some representations of directories contain a trailing separator character
* Changes in which exceptions are thrown (sometimes these are platform-dependent on CoreFX)

Issues:
* https://github.com/dotnet/corefx/issues/33486
* https://github.com/dotnet/corefx/issues/33490

Part of #7246
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants