Skip to content

Git - fileSystemProvider does not return an error when a file does not exist #204231

Closed
@ggrossetie

Description

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

Versions

Version : 1.86.0 (Universal)
Validation : 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date : 2024-01-31T10:29:15.765Z
Electron : 27.2.3
ElectronBuildId : 26495564
Chromium : 118.0.5993.159
Node.js : 18.17.1
V8 : 11.8.172.18-electron.0
Système d’exploitation : Darwin arm64 23.2.0

Steps to Reproduce:

  • stat will return a FileStat even if the file does not exist:

    async stat(uri: Uri): Promise<FileStat> {
    await this.model.isInitialized;
    const { submoduleOf, path, ref } = fromGitUri(uri);
    const repository = submoduleOf ? this.model.getRepository(submoduleOf) : this.model.getRepository(uri);
    if (!repository) {
    throw FileSystemError.FileNotFound();
    }
    let size = 0;
    try {
    const details = await repository.getObjectDetails(sanitizeRef(ref, path, repository), path);
    size = details.size;
    } catch {
    // noop
    }
    return { type: FileType.File, size: size, mtime: this.mtime, ctime: 0 };
    }

  • readFile will return an empty Uint8Array if the file does not exist:

    async readFile(uri: Uri): Promise<Uint8Array> {
    await this.model.isInitialized;
    const { path, ref, submoduleOf } = fromGitUri(uri);
    if (submoduleOf) {
    const repository = this.model.getRepository(submoduleOf);
    if (!repository) {
    throw FileSystemError.FileNotFound();
    }
    const encoder = new TextEncoder();
    if (ref === 'index') {
    return encoder.encode(await repository.diffIndexWithHEAD(path));
    } else {
    return encoder.encode(await repository.diffWithHEAD(path));
    }
    }
    const repository = this.model.getRepository(uri);
    if (!repository) {
    throw FileSystemError.FileNotFound();
    }
    const timestamp = new Date().getTime();
    const cacheValue: CacheRow = { uri, timestamp };
    this.cache.set(uri.toString(), cacheValue);
    try {
    return await repository.buffer(sanitizeRef(ref, path, repository), path);
    } catch (err) {
    return new Uint8Array(0);
    }
    }

The documentation is unclear about non existing file but VS Code has a FileSystemError.FileNotFound() error.

Is that expected? And if so, how can I check if a file exists or not when the Git fileSystemProvider is enabled. I thought about using the size property but I can't tell if it's an empty file or a non-existing file.

Maybe we should add an extra property to tell if the file exists in the working tree or not? Also, I do think that we should return a FileSystemError.FileNotFound() when trying to read a file that does not exist in the working tree.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable buggitGIT issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions