in src/commands/downloadFile.ts [62:142]
async function getAzCopyDownloads(context: IActionContext, destinationFolder: string, treeItems: AzExtTreeItem[]): Promise<IAzCopyDownload[]> {
const allFolderDownloads: IAzCopyDownload[] = [];
const allFileDownloads: IAzCopyDownload[] = [];
for (const treeItem of treeItems) {
if (treeItem instanceof BlobTreeItem) {
await treeItem.checkCanDownload(context);
allFileDownloads.push({
remoteFileName: treeItem.blobName,
remoteFilePath: treeItem.blobPath,
localFilePath: join(destinationFolder, treeItem.blobName),
fromTo: 'BlobLocal',
isDirectory: false,
treeItem,
});
} else if (treeItem instanceof BlobDirectoryTreeItem) {
allFolderDownloads.push({
remoteFileName: treeItem.dirName,
remoteFilePath: treeItem.dirPath,
localFilePath: join(destinationFolder, treeItem.dirName),
fromTo: 'BlobLocal',
isDirectory: true,
treeItem
});
} else if (treeItem instanceof FileTreeItem) {
allFileDownloads.push({
remoteFileName: treeItem.fileName,
remoteFilePath: posix.join(treeItem.directoryPath, treeItem.fileName),
localFilePath: join(destinationFolder, treeItem.fileName),
fromTo: 'FileLocal',
isDirectory: false,
treeItem,
});
} else if (treeItem instanceof DirectoryTreeItem) {
allFolderDownloads.push({
remoteFileName: treeItem.directoryName,
remoteFilePath: posix.join(treeItem.parentPath, treeItem.directoryName),
localFilePath: join(destinationFolder, treeItem.directoryName),
fromTo: 'FileLocal',
isDirectory: true,
treeItem
});
}
}
let hasParent: boolean;
const overwriteChoice: { choice: OverwriteChoice | undefined } = { choice: undefined };
const foldersToDownload: IAzCopyDownload[] = [];
const filesToDownload: IAzCopyDownload[] = [];
// Only download folders and files if their containing folder isn't already being downloaded.
for (const folderDownload of allFolderDownloads) {
hasParent = false;
for (const parentFolderDownload of allFolderDownloads) {
if (folderDownload !== parentFolderDownload && isSubpath(parentFolderDownload.remoteFilePath, folderDownload.remoteFilePath)) {
hasParent = true;
break;
}
}
if (!hasParent && await checkCanDownload(context, folderDownload.localFilePath, overwriteChoice)) {
foldersToDownload.push(folderDownload);
}
}
for (const fileDownload of allFileDownloads) {
hasParent = false;
for (const parentFolderDownload of allFolderDownloads) {
if (isSubpath(parentFolderDownload.remoteFilePath, fileDownload.remoteFilePath)) {
hasParent = true;
break;
}
}
if (!hasParent && await checkCanDownload(context, fileDownload.localFilePath, overwriteChoice)) {
filesToDownload.push(fileDownload);
}
}
return [...foldersToDownload, ...filesToDownload];
}