Support trimmed paths in FileInfo#27809
Conversation
Some paths are not creatable in Windows without special syntax. Notably paths with trailing spaces and periods. As GetFullPath() (and GetFullPathName()) trim these we would lose the correct file name as we passed the path around. With the enumeration changes we now populate FileInfo correctly- this change allows the other methods to work when wrapped around such a path.
| // | ||
| /// <summary> | ||
| /// Copies an existing file to a new file. | ||
| /// If <paramref name="overwrite"/> is false, and exception will be |
| // | ||
| // Your application must have Delete permission to the target file. | ||
| // | ||
| // or a file that is memory mapped. |
| } | ||
|
|
||
|
|
||
| // Tests if a file exists. The result is true if the file |
There was a problem hiding this comment.
If you feel like changing it, "if" -> "whether"
| FileInfo[] files = directory.GetFiles(); | ||
| Assert.Equal(2, files.Length); | ||
|
|
||
| FileInfo destination = new FileInfo(Path.Join(directory.FullName, GetTestFilePath())); |
There was a problem hiding this comment.
Maybe add "DeleteTestFilePath" to FileCleanupTestBase? Dispose can call it.
There was a problem hiding this comment.
Not sure what you're suggesting here.
| string fullPath = Path.GetFullPath(path); | ||
|
|
||
| FileSystem.DeleteFile(fullPath); | ||
| FileSystem.DeleteFile(Path.GetFullPath(path)); |
There was a problem hiding this comment.
Do we always call GetFullPath immediately on paths passed in to IO API? This is presumably in case current directory changes?
There was a problem hiding this comment.
Yes, we always call GetFullPath(). The current directory thing would impact things, and in some cases we need to know that the path is normalized. Historically I'm sure it was more about CAS and the preemptive checks we made in GFP than anything else.
Remove NotSupported and SecurityException from Exists as these are no longer thrown. Add a test fix I hadn't staged correctly.
| DirectoryInfo directory = Directory.CreateDirectory(GetTestFilePath()); | ||
| string fileOne = Path.Join(directory.FullName, "Trailing space "); | ||
| string fileTwo = Path.Join(directory.FullName, "Trailing period."); | ||
| File.Create(@"\\?\" + fileOne).Dispose(); |
There was a problem hiding this comment.
To close the file handle right away so it doesn't stay locked past this point.
|
@dotnet-bot test NETFX x86 Release Build Appears to have hung up running System.Net.Http.Functional.Tests |
|
@dotnet-bot test NETFX x86 Release Build please (hang now fixed) |
* Support trimmed paths in FileInfo Some paths are not creatable in Windows without special syntax. Notably paths with trailing spaces and periods. As GetFullPath() (and GetFullPathName()) trim these we would lose the correct file name as we passed the path around. With the enumeration changes we now populate FileInfo correctly- this change allows the other methods to work when wrapped around such a path. * Tweak comments. Remove NotSupported and SecurityException from Exists as these are no longer thrown. Add a test fix I hadn't staged correctly.
* Support trimmed paths in FileInfo Some paths are not creatable in Windows without special syntax. Notably paths with trailing spaces and periods. As GetFullPath() (and GetFullPathName()) trim these we would lose the correct file name as we passed the path around. With the enumeration changes we now populate FileInfo correctly- this change allows the other methods to work when wrapped around such a path. * Tweak comments. Remove NotSupported and SecurityException from Exists as these are no longer thrown. Add a test fix I hadn't staged correctly. Commit migrated from dotnet/corefx@41a2120
Some paths are not creatable in Windows without special syntax. Notably paths with trailing spaces and periods. As GetFullPath() (and GetFullPathName()) trim these we would lose the correct file name as we passed the path around. With the enumeration changes we now populate FileInfo correctly- this change allows the other methods to work when wrapped around such a path.
Also remove some CAS related comments.
cc: @jkotas, @Anipik, @danmosemsft, @pjanotti