Skip to content

Commit d2f51ac

Browse files
Dan MoseleyCopilot
andauthored
Add CreateTempSubdirectory cross-references to GetTempPath docs (#12606)
* Add CreateTempSubdirectory cross-references to GetTempPath docs - On GetTempPath Linux tab: add reference to Directory.CreateTempSubdirectory as a secure alternative to the shared /tmp/ directory - On GetTempPath macOS tab: add similar reference for the /tmp/ fallback case - On Directory.CreateTempSubdirectory: fill in remarks explaining owner-only permissions (700) on Unix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Use [!CAUTION] callout for security notes on GetTempPath Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review: may -> might per style guidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix MacOS -> macOS casing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 49dfed0 commit d2f51ac

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

xml/System.IO/Directory.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,15 @@ An I/O error occurred.</exception>
505505
<param name="prefix">An optional string to add to the beginning of the subdirectory name.</param>
506506
<summary>Creates a uniquely named, empty directory in the current user's temporary directory.</summary>
507507
<returns>An object that represents the directory that was created.</returns>
508-
<remarks>To be added.</remarks>
508+
<remarks>
509+
<format type="text/markdown"><![CDATA[
510+
511+
## Remarks
512+
513+
This method creates a new directory with a unique name under the path returned by <xref:System.IO.Path.GetTempPath*>. On Unix-like operating systems, the parent temporary directory might be shared among all users, whereas the directory created by <xref:System.IO.Directory.CreateTempSubdirectory*> is created with owner-only permissions (`700`).
514+
515+
]]></format>
516+
</remarks>
509517
<exception cref="T:System.ArgumentException">
510518
<paramref name="prefix" /> contains a directory separator.</exception>
511519
<exception cref="T:System.IO.IOException">A new directory cannot be created.</exception>

xml/System.IO/Path.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,11 +2203,14 @@ If the current Windows version exposes the [`GetTempPath2`](https://learn.micros
22032203
22042204
On Windows versions that don't expose GetTempPath2, this method instead invokes the [`GetTempPath`](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppathw) Win32 API and returns the resolved path. For more information on how this resolution is performed, including how to control the return value through the use of environment variables, see [the _Remarks_ section](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppathw#remarks) of the GetTempPath documentation.
22052205
2206-
# [MacOS](#tab/macos)
2206+
# [macOS](#tab/macos)
22072207
2208-
If the `TMPDIR` environment variable has been set, this method returns the value specified by that environment variable. MacOS sets `TMPDIR` on login to a per-user temporary directory.
2208+
If the `TMPDIR` environment variable has been set, this method returns the value specified by that environment variable. macOS sets `TMPDIR` on login to a per-user temporary directory.
22092209
2210-
Otherwise, this method returns `/tmp/`.
2210+
Otherwise, this method returns `/tmp/`, which is shared among all users.
2211+
2212+
> [!CAUTION]
2213+
> If your application needs a private temporary directory, use <xref:System.IO.Directory.CreateTempSubdirectory*>, which creates a subdirectory with owner-only permissions (`700`).
22112214
22122215
# [Linux](#tab/linux)
22132216
@@ -2216,6 +2219,9 @@ If the `TMPDIR` environment variable has been set, this method returns the value
22162219
Otherwise, this method returns `/tmp/`.
22172220
The `/tmp/` directory on Linux is commonly shared among all users (`1777` permissions); ensure this meets your application's security needs.
22182221
2222+
> [!CAUTION]
2223+
> If your application needs a private temporary directory, use <xref:System.IO.Directory.CreateTempSubdirectory*>, which creates a subdirectory with owner-only permissions (`700`).
2224+
22192225
---
22202226
22212227
## Examples

0 commit comments

Comments
 (0)