public void TestClose_directoryDeleted() { using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory(temporaryFolder.NewFolder().ToPath())) { CreateFilesInDirectory(temporaryDirectory.GetDirectory()); temporaryDirectory.Dispose(); Assert.IsFalse(Files.Exists(temporaryDirectory.GetDirectory())); } }
/** * Writes a compressed layer {@link Blob}. * * <p>The {@code compressedLayerBlob} is written to the layer directory under the layers directory * corresponding to the layer blob. * * @param compressedLayerBlob the compressed layer {@link Blob} to write out * @return the {@link CachedLayer} representing the written entry * @throws IOException if an I/O exception occurs */ public async Task <CachedLayer> WriteCompressedAsync(IBlob compressedLayerBlob) { compressedLayerBlob = compressedLayerBlob ?? throw new ArgumentNullException(nameof(compressedLayerBlob)); // Creates the layers directory if it doesn't exist. Files.CreateDirectories(cacheStorageFiles.GetLayersDirectory()); // Creates the temporary directory. Files.CreateDirectories(cacheStorageFiles.GetTemporaryDirectory()); using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory(cacheStorageFiles.GetTemporaryDirectory())) { SystemPath temporaryLayerDirectory = temporaryDirectory.GetDirectory(); // Writes the layer file to the temporary directory. WrittenLayer writtenLayer = await WriteCompressedLayerBlobToDirectoryAsync(compressedLayerBlob, temporaryLayerDirectory).ConfigureAwait(false); // Moves the temporary directory to the final location. temporaryDirectory.MoveIfDoesNotExist(cacheStorageFiles.GetLayerDirectory(writtenLayer.LayerDigest)); // Updates cachedLayer with the blob information. SystemPath layerFile = cacheStorageFiles.GetLayerFile(writtenLayer.LayerDigest, writtenLayer.LayerDiffId); return(CachedLayer.CreateBuilder() .SetLayerDigest(writtenLayer.LayerDigest) .SetLayerDiffId(writtenLayer.LayerDiffId) .SetLayerSize(writtenLayer.LayerSize) .SetLayerBlob(Blobs.From(layerFile)) .Build()); } }
public void TestClose_directoryNotDeletedIfMoved() { SystemPath destinationParent = temporaryFolder.NewFolder().ToPath(); using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory(temporaryFolder.NewFolder().ToPath())) { CreateFilesInDirectory(temporaryDirectory.GetDirectory()); Assert.IsFalse(Files.Exists(destinationParent.Resolve("destination"))); Files.Move(temporaryDirectory.GetDirectory(), destinationParent.Resolve("destination")); temporaryDirectory.Dispose(); Assert.IsFalse(Files.Exists(temporaryDirectory.GetDirectory())); Assert.IsTrue(Files.Exists(destinationParent.Resolve("destination"))); } }
public to_long_paths() { // establish _temporaryDirectory = FileSystem.CreateTempDirectory(); _temporaryDirectory.Exists().Should().Be.True(); _temporaryDirectory.Should().Not.Be.Null(); // given _directoryName = RandomName(15); _dir = _temporaryDirectory.GetDirectory(_directoryName); _dir.Should().Not.Be.Null(); _dir.MustExist(); }
public string GetApplicationLayersCacheDirectory() { if (applicationLayersCacheDirectory == null) { // Uses a temporary directory if application layers cache directory is not set. try { tempAppLayersCacheDir = new TemporaryDirectory(Path.GetTempPath()); applicationLayersCacheDirectory = tempAppLayersCacheDir.GetDirectory(); } catch (IOException ex) { throw new CacheDirectoryCreationException(ex); } } return(applicationLayersCacheDirectory); }
/** * Writes an uncompressed {@link Blob} out to the cache directory in the form: * * <ul> * <li>The {@code uncompressedLayerBlob} is written to the layer directory under the layers * directory corresponding to the layer blob. * <li>The {@code selector} is written to the selector file under the selectors directory. * </ul> * * @param uncompressedLayerBlob the {@link Blob} containing the uncompressed layer contents to * write out * @param selector the optional selector digest to also reference this layer data. A selector * digest may be a secondary identifier for a layer that is distinct from the default layer * digest. * @return the {@link CachedLayer} representing the written entry * @throws IOException if an I/O exception occurs */ public async Task <CachedLayer> WriteUncompressedAsync(IBlob uncompressedLayerBlob, DescriptorDigest selector) { uncompressedLayerBlob = uncompressedLayerBlob ?? throw new ArgumentNullException(nameof(uncompressedLayerBlob)); // Creates the layers directory if it doesn't exist. Files.CreateDirectories(cacheStorageFiles.GetLayersDirectory()); // Creates the temporary directory. The temporary directory must be in the same FileStore as the // final location for Files.move to work. Files.CreateDirectories(cacheStorageFiles.GetTemporaryDirectory()); using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory(cacheStorageFiles.GetTemporaryDirectory())) { SystemPath temporaryLayerDirectory = temporaryDirectory.GetDirectory(); // Writes the layer file to the temporary directory. WrittenLayer writtenLayer = await WriteUncompressedLayerBlobToDirectoryAsync(uncompressedLayerBlob, temporaryLayerDirectory).ConfigureAwait(false); // Moves the temporary directory to the final location. temporaryDirectory.MoveIfDoesNotExist(cacheStorageFiles.GetLayerDirectory(writtenLayer.LayerDigest)); // Updates cachedLayer with the blob information. SystemPath layerFile = cacheStorageFiles.GetLayerFile(writtenLayer.LayerDigest, writtenLayer.LayerDiffId); CachedLayer.Builder cachedLayerBuilder = CachedLayer.CreateBuilder() .SetLayerDigest(writtenLayer.LayerDigest) .SetLayerDiffId(writtenLayer.LayerDiffId) .SetLayerSize(writtenLayer.LayerSize) .SetLayerBlob(Blobs.From(layerFile)); // Write the selector file. if (selector != null) { WriteSelector(selector, writtenLayer.LayerDigest); } return(cachedLayerBuilder.Build()); } }