Skip to content

Recover from ENOENT due to missing parent dir when trusting notebook #12913

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

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/client/datascience/interactive-ipynb/digestStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ export class DigestStorage implements IDigestStorage {
public async saveDigest(uri: Uri, signature: string) {
const fileLocation = await this.getFileLocation(uri);
// Since the signature is a hex digest, the character 'z' is being used to delimit the start and end of a single digest
await this.fs.appendFile(fileLocation, `z${signature}z\n`);
try {
await this.fs.appendFile(fileLocation, `z${signature}z\n`);
} catch (err) {
// The nbsignatures dir is only initialized on extension activation.
// If the user deletes it to reset trust, the next attempt to trust
// an untrusted notebook in the same session will fail because the parent
// directory does not exist.
if (isFileNotFoundError(err)) {
// Gracefully recover from such errors by reinitializing directory and retrying
await this.initDir();
await this.fs.appendFile(fileLocation, `z${signature}z\n`);
} else {
traceError(err);
}
}
}

public async containsDigest(uri: Uri, signature: string) {
Expand Down