public async Task DownloadApplicationBinaries(AppIdentity appIdentity, string localPath, ConflictResolutionMode conflictResolutionMode) { bool exists = !FileUtils.DirectoryDoesntExistOrEmpty(localPath); if (exists) { if (conflictResolutionMode == ConflictResolutionMode.DoNothingIfBinariesExist) { return; } if (conflictResolutionMode == ConflictResolutionMode.FailIfBinariesExist) { throw new DuplicateBinariesException( $"Cannot download the binaries because the destination directory {localPath} contains files"); } } CloudBlobDirectory blobDirectory = GetBlobDirectory(appIdentity); if (!await blobDirectory.ExistsAsync()) { throw new BinariesNotFoundException("The binaries were not found in the Yams repository"); } await BlobUtils.DownloadBlobDirectory(blobDirectory, localPath); }
public async Task TestDownloadBlobsFromBlobDirectory() { // First create the file hierarchy in the blob storage CloudBlobDirectory root = await CreateBlobsTree(); // The upload the directory to a local temporary folder var tempPath = GetTestDirPath(nameof(TestDownloadBlobsFromBlobDirectory)); var appPath = Path.Combine(tempPath, "app\\1.0.0"); await BlobUtils.DownloadBlobDirectory(root, appPath); ISet <string> relativePathSet = new HashSet <string>(); foreach (var path in FileUtils.ListFilesRecursively(appPath)) { var relPath = FileUtils.GetRelativePath(appPath, path); relativePathSet.Add(relPath); } // Then verify that the hierachy on the local file system matches the one in the blob directory VerifyThatAllFilesAreThere(relativePathSet, "\\"); // get the modified data of d1/b1 string d1b1Path = Path.Combine(appPath, "d1", "b1"); DateTime d1b1WriteTime = File.GetLastWriteTimeUtc(d1b1Path); // delete and modify some files to make sure that they will be download File.Delete(Path.Combine(appPath, "b1")); File.Delete(Path.Combine(appPath, "d1", "b2")); // modify a file to make sure it'll be replaced string b2FilePath = Path.Combine(appPath, "b2"); DateTime b2WriteTime = File.GetLastWriteTimeUtc(b2FilePath); File.WriteAllText(b2FilePath, "blabla"); Assert.Equal("blabla", File.ReadAllText(b2FilePath)); await BlobUtils.DownloadBlobDirectory(root, appPath); VerifyThatAllFilesAreThere(relativePathSet, "\\"); string newFileContent = File.ReadAllText(b2FilePath); Assert.Equal(d1b1WriteTime, File.GetLastWriteTimeUtc(d1b1Path)); Assert.NotEqual(b2WriteTime, File.GetLastWriteTimeUtc(b2FilePath)); }
public async Task TestDownloadBlobsFromBlobDirectory() { // First create the file hierarchy in the blob storage CloudBlobDirectory root = await CreateBlobsTree(); // The upload the directory to a local temporary folder var tempPath = GetTestDirPath(nameof(TestDownloadBlobsFromBlobDirectory)); var appPath = Path.Combine(tempPath, "app\\1.0.0"); await BlobUtils.DownloadBlobDirectory(root, appPath); ISet <string> relativePathSet = new HashSet <string>(); foreach (var path in FileUtils.ListFilesRecursively(appPath)) { var relPath = FileUtils.GetRelativePath(appPath, path); relativePathSet.Add(relPath); } // Then verify that the hierachy on the local file system matches the one in the blob directory VerifyThatAllFilesAreThere(relativePathSet, "\\"); }
public async Task TestDownloadBlobsFromBlobDirectory() { CloudBlobContainer container = _blobClient.GetContainerReference("container"); container.CreateIfNotExists(); CloudBlobDirectory root = container.GetDirectoryReference("root"); ICloudBlob b1 = root.GetBlockBlobReference("b1"); await BlobUtils.CreateEmptyBlob(b1); ICloudBlob b2 = root.GetBlockBlobReference("b2"); await BlobUtils.CreateEmptyBlob(b2); CloudBlobDirectory d1 = root.GetDirectoryReference("d1"); ICloudBlob d1b1 = d1.GetBlockBlobReference("b1"); ICloudBlob d1b2 = d1.GetBlockBlobReference("b2"); await BlobUtils.CreateEmptyBlob(d1b1); await BlobUtils.CreateEmptyBlob(d1b2); CloudBlobDirectory d2 = root.GetDirectoryReference("d2"); ICloudBlob d2b3 = d2.GetBlockBlobReference("b3"); ICloudBlob d2b4 = d2.GetBlockBlobReference("b4"); await BlobUtils.CreateEmptyBlob(d2b3); await BlobUtils.CreateEmptyBlob(d2b4); CloudBlobDirectory d2d3 = d2.GetDirectoryReference("d3"); ICloudBlob d2d3b5 = d2d3.GetBlockBlobReference("b5"); ICloudBlob d2d3b6 = d2d3.GetBlockBlobReference("b6"); await BlobUtils.CreateEmptyBlob(d2d3b5); await BlobUtils.CreateEmptyBlob(d2d3b6); await BlobUtils.CreateEmptyBlob( root.GetDirectoryReference("d4").GetDirectoryReference("d5").GetBlockBlobReference("b7")); // The hierarchy in the blob storage is as follows: // // root // |__b1 // |__b2 // |__d1 // | |__b1 // | |__b2 // |__d2 // | |__b3 // | |__b4 // | |__d3 // | | |__b5 // | | |__b6 // |__d4 // | |__d5 // | | |__b7 string tempPath = Path.Combine(Path.GetTempPath(), "TestDownloadBlobsFromBlobDirectory"); await BlobUtils.DownloadBlobDirectory(root, tempPath); ISet <string> relativePathSet = new HashSet <string>(); foreach (string path in Directory.GetFiles(tempPath, "*.*", SearchOption.AllDirectories)) { string hash = path.Remove(0, tempPath.Length); relativePathSet.Add(hash); } Assert.AreEqual(9, relativePathSet.Count); Assert.IsTrue(relativePathSet.Contains("\\b1")); Assert.IsTrue(relativePathSet.Contains("\\b2")); Assert.IsTrue(relativePathSet.Contains("\\d1\\b1")); Assert.IsTrue(relativePathSet.Contains("\\d1\\b2")); Assert.IsTrue(relativePathSet.Contains("\\d2\\b3")); Assert.IsTrue(relativePathSet.Contains("\\d2\\b4")); Assert.IsTrue(relativePathSet.Contains("\\d2\\d3\\b5")); Assert.IsTrue(relativePathSet.Contains("\\d2\\d3\\b6")); Assert.IsTrue(relativePathSet.Contains("\\d4\\d5\\b7")); }
public Task Download(string destPath) { return(BlobUtils.DownloadBlobDirectory(_cloudBlobDirectory, destPath)); }