public async Task TestUploadDirectory() { // First create the file hierarchy on the local file system var rootPath = await CreateLocalFileTree(nameof(TestUploadDirectory)); // Then upload the directory to blob storage var container = _blobClient.GetContainerReference("container"); container.CreateIfNotExists(); string blobDirPath = $"{nameof(TestUploadDirectory)}/app/1.0.0"; await BlobUtils.UploadDirectory(rootPath, container, blobDirPath); var blobDirectory = container.GetDirectoryReference(blobDirPath); var blobs = await blobDirectory.ListBlobsAsync(); ISet <string> relativePathSet = new HashSet <string>(); foreach (var blobItem in blobs) { var blob = (CloudBlockBlob)blobItem; var relPath = BlobUtils.GetBlobRelativePath(blob, blobDirectory); relativePathSet.Add(relPath); } // Then verify that the hierachy on the blob storage matches the one the local file system VerifyThatAllFilesAreThere(relativePathSet, "/"); }
public async Task UploadApplicationBinaries(AppIdentity appIdentity, string localPath, ConflictResolutionMode conflictResolutionMode) { if (FileUtils.DirectoryDoesntExistOrEmpty(localPath)) { throw new BinariesNotFoundException( $"Binaries were not be uploaded because they were not found at the given path {localPath}"); } if (conflictResolutionMode == ConflictResolutionMode.OverwriteExistingBinaries) { await DeleteApplicationBinaries(appIdentity); } else { bool exists = await HasApplicationBinaries(appIdentity); if (exists) { if (conflictResolutionMode == ConflictResolutionMode.DoNothingIfBinariesExist) { return; } if (conflictResolutionMode == ConflictResolutionMode.FailIfBinariesExist) { throw new DuplicateBinariesException( $"Cannot override binaries when flag {ConflictResolutionMode.FailIfBinariesExist} is used"); } } } // at this point we know that it is either OverwriteExistingBinaries mode or the binaries don't exist await BlobUtils.UploadDirectory(localPath, _blobContainer, GetBlobDirectoryRelPath(appIdentity)); }