Skip to content

IFileSystem.fileExists returns false even when a file exists. #8890

Closed

Description

This breaks conda and virtual environments

  • These environments are no longer listed as interpreters, hence absolutely nothing works for conda or virtual environments.

In master.
I believe the logic of checking the file stat is incorrect.
We're checking if the file type == FIle when checking if a file exists.
However fstat could indicate that its a symbolic link.

Not sure this is the issue, but likely. Either way still is incorrect.

I.e. I don't think we should be comparing == File, we might want to check if !== Directory instead. I.e. allow other values except directory. I.e. its possible Unknown could be returned for a file (just as with symbolic links & others).

Proposed solution

  • If checking for a file, then ensure fstat !== direcrtory
  • If checking for a directory, then ensure fstat !== file

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    triage-neededNeeds assignment to the proper sub-team
    on Dec 4, 2019
  2. changed the title [-]IFileSystem.fileExists returns true even when a file exists.[/-] [+]IFileSystem.fileExists returns false even when a file exists.[/+] on Dec 4, 2019
  3. DonJayamanne commented on Dec 4, 2019

    @DonJayamanne
    Author

    The problem is we're treating the FileType as an enum and comparing ===.
    However these are bit values and we need to use bitwise operations.

  4. DonJayamanne commented on Dec 4, 2019

    @DonJayamanne
    Author

    Other issues across the code:

    • We have other issues in the code as well if (await this.fs.fileExists(dir)) {
      • Tests cannot catch this. Its possible we've made similar mistakes elsewhere (possibly due to find replace).
    • Checking === instead of using bitwise operations.
        public async getFiles(dirname: string): Promise<string[]> {
            return (await this.listdir(dirname))
                .filter(([_name, fileType]) => fileType === FileType.File)
                .map(([name, _fileType]) => this.paths.join(dirname, name));
        }
    

    Eric Snow (@ericsnowcurrently) Karthik Nadig (@karthiknadig) /cc

  5. ericsnowcurrently commented on Dec 4, 2019

    @ericsnowcurrently

    The old code for fileExists() used fs.Stats.isFile(), which is equivalent to checking for FileType.File. I don't think there's a need to change that approach.

  6. DonJayamanne commented on Dec 4, 2019

    @DonJayamanne
    Author

    Eric Snow (@ericsnowcurrently)
    Please see my comment here #8890 (comment)
    That's where the bug is.

  7. ericsnowcurrently commented on Dec 4, 2019

    @ericsnowcurrently

    Right. I have a fix for that. :)

  8. locked as resolved and limited conversation to collaborators on Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions