Skip to content

Commit

Permalink
Allow trailing slashes for directories, not for files/blobs (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
William Lorey committed Jan 21, 2020
1 parent 9d9ba89 commit 73bea34
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/AzureStorageFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
return await callWithTelemetryAndErrorHandling('stat', async (context) => {
context.telemetry.suppressIfSuccessful = true;

if (uri.path.endsWith('/')) {
// Ignore trailing forward slashes
// https://github.com/microsoft/vscode-azurestorage/issues/576
uri = uri.with({ path: uri.path.slice(0, -1) });
}

let treeItem: AzureStorageTreeItem = await this.lookup(uri, context);
let fileType: vscode.FileType = treeItem instanceof DirectoryTreeItem || treeItem instanceof FileShareTreeItem || treeItem instanceof BlobDirectoryTreeItem || treeItem instanceof BlobContainerTreeItem ? vscode.FileType.Directory : vscode.FileType.File;

Expand Down Expand Up @@ -188,6 +195,14 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
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;
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);
let parsedUri = this.parseUri(uri);
let treeItem: FileShareTreeItem | BlobContainerTreeItem = await this.lookupRoot(uri, context, parsedUri.resourceId);
Expand Down

0 comments on commit 73bea34

Please sign in to comment.