Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DonJayamanne opened this issue Dec 4, 2019 · 5 comments
Closed

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

DonJayamanne opened this issue Dec 4, 2019 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@DonJayamanne
Copy link

DonJayamanne commented Dec 4, 2019

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
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug P0 triage-needed Needs assignment to the proper sub-team labels Dec 4, 2019
@DonJayamanne DonJayamanne changed the title IFileSystem.fileExists returns true even when a file exists. IFileSystem.fileExists returns false even when a file exists. Dec 4, 2019
@ericsnowcurrently ericsnowcurrently added feature-* and removed triage-needed Needs assignment to the proper sub-team labels Dec 4, 2019
@ericsnowcurrently ericsnowcurrently self-assigned this Dec 4, 2019
@DonJayamanne
Copy link
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.

@DonJayamanne
Copy link
Author

DonJayamanne commented Dec 4, 2019

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));
    }

@ericsnowcurrently @karthiknadig /cc

@ericsnowcurrently
Copy link

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.

@DonJayamanne
Copy link
Author

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

@ericsnowcurrently
Copy link

Right. I have a fix for that. :)

ericsnowcurrently added a commit that referenced this issue Dec 10, 2019
(for #8890)

The plan is to un-revert this stuff bit-by-bit.

* Revert "Fixes to FileSystem code to use bitwise operations (#8966)"
This reverts commit acb59d3.

* Revert "Make sure IFileSystem is registered in DI during tests. (#8902)"
This reverts commit dabd87f.

* Revert "Remove IFileSystemUtils from IOC container (#8898)"
This reverts commit 8ab93d7.

* Revert "Skip a few more tests. (#8830)"
This reverts commit d197557.

* Revert "Skip problematic tests. (#8810)"
This reverts commit c5f7766.

* Revert "Use new VS Code filesystem API. (#8307)"
This reverts commit 7cbd1c2.

* Revert "Update the code base to use IFileSystem instead of fs and fs-extra. (#7915)"
This reverts commit a23761d.
@ghost ghost removed the needs PR label Dec 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

5 participants