Uh oh!
There was an error while loading. Please reload this page.
Add Directory.CreateTempSubdirectory - #73408
Conversation
CreateTempSubdirectory will create a new uniquely named directory under the temp directory. This allows applications to write temporary files in a co-located directory. Contributes to dotnet#72881
ghost
commented
Aug 4, 2022
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost
commented
Aug 4, 2022
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsCreateTempSubdirectory will create a new uniquely named directory under the temp directory. This allows applications to write temporary files in a co-located directory. Contributes to #72881 Note: I've decided not to implement the full approved API in #72881 because of the feedback on the File API. That will be added in a future PR.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| while (attempts < MaxAttempts) | ||
| { | ||
| Interop.GetRandomBytes(pKey, RandomKeyLength); | ||
| Path.Populate83FileNameFromRandomBytes(pKey, RandomKeyLength, builder.RawChars.Slice(builder.Length, RandomFileNameLength)); |
There was a problem hiding this comment.
Why is it important to use the 8.3 naming?
There was a problem hiding this comment.
It isn't important. But it is what GetRandomFileName uses
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
Lines 281 to 289 in 916f1ad
I'm just simulating a call to GetRandomFileName here, without allocating an intermediate string.
There was a problem hiding this comment.
I can add a comment here, if that helps. Or did you have a different algorithm in mind for generating a folder name?
There was a problem hiding this comment.
IMO having a period in the directory name seems a bit strange
There was a problem hiding this comment.
IMO having a period in the directory name seems a bit strange
Does it really matter though? Code shouldn't depend on these names - they even have a different pattern between Windows and Unix. Besides, there are plenty of cases where directories have periods in their names - versions, namespace-like, etc.
e.g. C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.7.
jozkee
left a comment
There was a problem hiding this comment.
Other than existing comments and a few more I'm leaving, LGTM.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Rewrite CreateTempSubdirectory and GetTempFileName on Unix to minimize allocations.
eerhardt
commented
Aug 5, 2022
I have responded to all existing feedback and pushed new changes. PTAL. |
Uh oh!
There was an error while loading. Please reload this page.
| namespace System.IO.Tests | ||
| { | ||
| public class Directory_CreateTempSubdirectory : FileSystemTest |
There was a problem hiding this comment.
Maybe verify that the filemode of the created directory is 700 on Unix. That is an important trait of this API.
There was a problem hiding this comment.
Q: is it on Windows also guaranteed the resulting directory is only accessible to the current user?
There was a problem hiding this comment.
Maybe verify that the filemode of the created directory is 700 on Unix.
Done.
Q: is it on Windows also guaranteed the resulting directory is only accessible to the current user?
No, on Windows there is no guarantee on the permissions of the directory. Just that it is empty, and it is in the TEMP directory.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot @eerhardt !
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…tests These tests had 3 methods that do the same thing. Consolidating down to one. Follow up to dotnet#73408
CreateTempSubdirectory will create a new uniquely named directory under the temp directory. This allows applications to write temporary files in a co-located directory.
Contributes to #72881
Note: I've decided not to implement the full approved API in #72881 because of the feedback on the File API. That will be added in a future PR.