microsoft / microsoft/terminal

Clean up CreateFile loop in ReadUTF8File

Open
#11,753 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-CodeHealth Area-Settings Issue-Task Product-Terminal
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

ReadUTF8File in the Settings library tries three times to read the settings file. If the size changes while it is being read, it'll try again.

Right now, the code looks like this (roughly):

while(tries) {
    open
    check permissions
    read in full
    check read size
}

It's expensive to open the file and check the permissions every time. Instead, we could:

open
check permissions
while (tries) {
    reset file pointer
    read in full
    check read size
}

That'll save us closing/reopening the file up to three times.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate ReadUTF8File in the Settings library and inspect its current retry loop. Confirm how the file pointer is reset and how permissions and read size are checked; done means the file is opened and permissions are checked once while retries reuse the open file without changing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.