示例#1
0
 public void Dispose()
 {
     try
     {
         _file.Dispose();
     }
     finally
     {
         PosixFile.DeleteOnClose(_tempFile);
     }
 }
示例#2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            var files = _tx.ReadTree(_tree);

            using (Slice.From(_tx.Allocator, _name, out Slice nameSlice))
            {
                _file.Seek(0, SeekOrigin.Begin);
                files.AddStream(nameSlice, _file);
            }

            _file.Dispose();
            PosixFile.DeleteOnClose(_fileTempPath);
        }
示例#3
0
 private void DisposeFile()
 {
     try
     {
         _file.Dispose();
     }
     catch (Exception e)
     {
         // we are done with this file, nothing we can do here
         if (Logger.IsInfoEnabled)
         {
             Logger.Info($"Failed to dispose the file: {_name} in path: {_fileTempPath}", e);
         }
     }
     finally
     {
         PosixFile.DeleteOnClose(_fileTempPath);
     }
 }
        public static async Task <Stream> CopyRemoteStreamLocally(Stream stream, PathSetting tempPath)
        {
            if (stream.CanSeek)
            {
                return(stream);
            }

            // This is meant to be used by ZipArchive, which will copy the data locally because is *must* be seekable.
            // To avoid reading everything to memory, we copy to a local file instead. Note that this also ensure that we
            // can process files > 2GB in size. https://github.com/dotnet/runtime/issues/59027
            var basePath = tempPath?.FullPath ?? Path.GetTempPath();
            var filePath = Path.Combine(basePath, $"{Guid.NewGuid()}.restore-local-file");
            var file     = SafeFileStream.Create(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read,
                                                 32 * 1024, FileOptions.DeleteOnClose);

            try
            {
                await stream.CopyToAsync(file);

                file.Seek(0, SeekOrigin.Begin);

                return(file);
            }
            catch
            {
                try
                {
                    await file.DisposeAsync();
                }
                catch
                {
                    // nothing we can do
                }
                finally
                {
                    PosixFile.DeleteOnClose(filePath);
                }

                throw;
            }
        }
示例#5
0
 public void Dispose()
 {
     _file.Dispose();
     PosixFile.DeleteOnClose(_tempFile);
 }