[PR #10908] [MERGED] Fix WriteUTF8FileAtomic to preserve symlinks #28298

Open
opened 2026-01-31 09:27:37 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10908
Author: @Don-Vito
Created: 8/9/2021
Status: Merged
Merged: 8/12/2021
Merged by: @undefined

Base: mainHead: 10787-preserve-settings-symlink


📝 Commits (6)

  • 432ba23 Fix WriteUTF8FileAtomic to preserve symlinks
  • 7500f4a Add symlink to spell-check
  • 6194358 Fix symlink resolution to support link to link
  • 7d261b4 Introduce canonical as a default implementation of link resolution
  • a267d6f Limit invocation of canonical only for symlinks
  • f5cd41e Restore removed line

📊 Changes

2 files changed (+23 additions, -2 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+1 -0)
📝 src/cascadia/TerminalSettingsModel/FileUtils.cpp (+22 -2)

📄 Description

WriteUTF8FileAtomic overrides the content of the file "atomically"
by creating a temp file and then renaming it to the original path.
The problem arises when the original path is symbolic link,
as the link itself gets overridden by a file (rather than the link target).
This PR introduces a special handling of the symlinks:
if the path as a symlink we resolve the path and use:

  1. target's directory to create a temp-file in
  2. target itself to be replaced with the tempfile.

Symlink resolution is problematic when the target path does not exist,
as there is no good utility that resolves such link (canonical() fails).
In this corner case we skip the "atomic" approach of renaming the file
and write the link target directly.

Closes #10787


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/10908 **Author:** [@Don-Vito](https://github.com/Don-Vito) **Created:** 8/9/2021 **Status:** ✅ Merged **Merged:** 8/12/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `10787-preserve-settings-symlink` --- ### 📝 Commits (6) - [`432ba23`](https://github.com/microsoft/terminal/commit/432ba23f5441de9756c7d080f2bcb1c13b870f1a) Fix WriteUTF8FileAtomic to preserve symlinks - [`7500f4a`](https://github.com/microsoft/terminal/commit/7500f4a27529b81feec92b47cb890d0ce545c655) Add symlink to spell-check - [`6194358`](https://github.com/microsoft/terminal/commit/61943586e1d2108e7646ee2fed7481355e568239) Fix symlink resolution to support link to link - [`7d261b4`](https://github.com/microsoft/terminal/commit/7d261b473963bc50e0900d544e50429c325e2ec1) Introduce canonical as a default implementation of link resolution - [`a267d6f`](https://github.com/microsoft/terminal/commit/a267d6f849475c6b954a88967d266b78863577b1) Limit invocation of canonical only for symlinks - [`f5cd41e`](https://github.com/microsoft/terminal/commit/f5cd41e7ac248c6c0a3bc2a3f31ba1a495114c11) Restore removed line ### 📊 Changes **2 files changed** (+23 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+1 -0) 📝 `src/cascadia/TerminalSettingsModel/FileUtils.cpp` (+22 -2) </details> ### 📄 Description WriteUTF8FileAtomic overrides the content of the file "atomically" by creating a temp file and then renaming it to the original path. The problem arises when the original path is symbolic link, as the link itself gets overridden by a file (rather than the link target). This PR introduces a special handling of the symlinks: if the path as a symlink we resolve the path and use: 1. target's directory to create a temp-file in 2. target itself to be replaced with the tempfile. Symlink resolution is problematic when the target path does not exist, as there is no good utility that resolves such link (canonical() fails). In this corner case we skip the "atomic" approach of renaming the file and write the link target directly. Closes #10787 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:27:37 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28298