Skip to content

History may use reserved filenames on windows #177138

Closed

Description

@fgma

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.76.1
  • OS Version: Windows 10

Steps to Reproduce:

Can't really provide some simple instructions to reproduce because random values generated by vscode during runtime are the actual issue.

After regular use I ended up with a file named "LPt4" in AppData\Roaming\Code\User\History. The filename is a reserved filename on windows like CON, COM1, LPT1 etc. The file can't be deleted by the user using windows explorer or accessed by normal tools which broke my backup software. Solution is to use del command in cmd.exe and provide a complete UNC path to delete the file.

Source of bug probably is in vscode/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.ts doAddEntry()

const id = `${randomPath(undefined, undefined, 4)}${extname(workingCopyResource)}`;

The file generated has a random 4 character prefix which by accident can be a reserved filename. I propose to just extend the length of the history filename so it is impossible to be a reserved filename on windows.

At least
this.historyEntriesNameMatcher = new RegExp(`[A-Za-z0-9]{4}${escapeRegExpCharacters(extname(workingCopyResource))}`);
would also need to be changed.

Activity

  1. added
    bug
    on Mar 15, 2023
  2. bpasero commented on Mar 15, 2023

    @bpasero
    Contributor

    Good catch, I think we need a random file path generator that also calls into this validator:

    export function isValidBasename(name: string | null | undefined, isWindowsOS: boolean = isWindows): boolean {

    I wonder if we have other places where this can happen. We should probably check.

  3. added a commit that references this issue on Mar 15, 2023
    9e6ff50
  4. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Mar 15, 2023
  5. added
    debt
    and removed
    bug
    on Mar 16, 2023
  6. locked and limited conversation to collaborators on Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debtinsiders-releasedtimeline-local-history

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions