async function uploadFilesHelper()

in src/commands/uploadFiles.ts [86:129]


async function uploadFilesHelper(
    context: IActionContext,
    treeItem: BlobContainerTreeItem | FileShareTreeItem,
    uris: Uri[],
    notificationProgress: NotificationProgress,
    cancellationToken: CancellationToken,
    destinationDirectory: string,
    calledFromUploadToAzureStorage: boolean
): Promise<IAzCopyResolution> {
    lastUriUpload = uris[0];
    const resolution: IAzCopyResolution = { errors: [] };
    for (const uri of uris) {
        throwIfCanceled(cancellationToken, context.telemetry.properties, 'uploadFiles');

        const localFilePath: string = uri.fsPath;
        const remoteFilePath: string = convertLocalPathToRemotePath(localFilePath, destinationDirectory);
        const id: string = `${treeItem.fullId}/${remoteFilePath}`;
        const result = await treeItem.treeDataProvider.findTreeItem(id, context);
        try {
            if (result) {
                // A treeItem for this file already exists, no need to do anything with the tree, just upload
                await treeItem.uploadLocalFile(context, localFilePath, remoteFilePath, notificationProgress, cancellationToken);
            } else {
                await treeItem.createChild(<IExistingFileContext>{ ...context, remoteFilePath, localFilePath });
            }
        } catch (error) {
            const parsedError: IParsedError = parseError(error);
            if (isAzCopyError(parsedError)) {
                resolution.errors.push(parsedError);
            } else {
                throw error;
            }
        }
    }

    if (calledFromUploadToAzureStorage || resolution.errors.length === 0) {
        // No need to throw any errors from this function
        return resolution;
    } else if (resolution.errors.length === 1) {
        throw resolution.errors[0];
    } else {
        throw new Error(multipleAzCopyErrorsMessage);
    }
}