in src/AzureStorageFS.ts [241:308]
await callWithTelemetryAndErrorHandling('writeFile', async (context) => {
if (!options.create && !options.overwrite) {
throw getFileSystemError(uri, context, vscode.FileSystemError.NoPermissions);
}
if (uri.path.endsWith('/')) {
// https://github.com/microsoft/vscode-azurestorage/issues/576
context.errorHandling.rethrow = true;
context.errorHandling.suppressDisplay = true;
void vscode.commands.executeCommand('workbench.files.action.refreshFilesExplorer'); // Show any parent directories that may have already been created
throw new Error("File/blob names with a trailing '/' are not allowed.");
}
const writeToFileShare: boolean = this.isFileShareUri(uri);
const parsedUri = this.parseUri(uri);
const treeItem: FileShareTreeItem | BlobContainerTreeItem = await this.lookupRoot(uri, context, parsedUri.resourceId);
let childExists: boolean;
try {
await this.lookup(uri, context);
childExists = true;
} catch {
childExists = false;
}
let childExistsRemote: boolean;
if (treeItem instanceof FileShareTreeItem) {
childExistsRemote = await doesFileExist(parsedUri.baseName, treeItem, parsedUri.parentDirPath, treeItem.shareName);
} else {
childExistsRemote = await doesBlobExist(treeItem, parsedUri.filePath);
}
if (childExists !== childExistsRemote) {
// Need to be extra careful here to prevent possible data-loss. Related to https://github.com/microsoft/vscode-azurestorage/issues/436
throw new Error(localize('outOfSync', 'Your Azure Storage file system is out of sync and must be refreshed.'));
}
if (!childExists && !options.create) {
throw getFileSystemError(uri, context, vscode.FileSystemError.FileNotFound);
} else if (childExists && !options.overwrite) {
throw getFileSystemError(uri, context, vscode.FileSystemError.FileExists);
} else {
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
if (childExists) {
progress.report({ message: `Saving ${writeToFileShare ? 'file' : 'blob'} ${parsedUri.filePath}` });
if (treeItem instanceof FileShareTreeItem) {
await updateFileFromText(parsedUri.parentDirPath, parsedUri.baseName, treeItem.shareName, treeItem.root, content.toString());
} else {
await createOrUpdateBlockBlob(treeItem, parsedUri.filePath, content.toString());
}
// NOTE: This is the only event handled directly in this class and not in the tree item
this.fireSoon({ type: vscode.FileChangeType.Changed, uri });
} else {
progress.report({ message: `Creating ${writeToFileShare ? 'file' : 'blob'} ${parsedUri.filePath}` });
const parentUri: vscode.Uri = AzureStorageFS.idToUri(parsedUri.resourceId, parsedUri.parentDirPath);
const parent = await this.lookupAsDirectory(parentUri, context, parsedUri.resourceId, parsedUri.parentDirPath);
if (writeToFileShare) {
await parent.createChild(<IFileShareCreateChildContext>{ ...context, childType: 'azureFile', childName: parsedUri.baseName });
} else {
await parent.createChild(<IBlobContainerCreateChildContext>{ ...context, childType: 'azureBlob', childName: parsedUri.filePath });
}
}
});
}
});