1
0
Эх сурвалжийг харах

Improving error reporting when merging parallel file parts fail

Source commit: 4ea577f294df45f8d830aff9aabd3e9655e02317
Martin Prikryl 2 жил өмнө
parent
commit
c7ab4b7329

+ 20 - 3
source/core/FileBuffer.cpp

@@ -246,10 +246,27 @@ void __fastcall TFileBuffer::WriteToOut(TTransferOutEvent OnTransferOut, TObject
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 __fastcall TSafeHandleStream::TSafeHandleStream(int AHandle) :
-  THandleStream(AHandle)
+  THandleStream(AHandle),
+  FSource(NULL)
 {
 }
 //---------------------------------------------------------------------------
+__fastcall TSafeHandleStream::TSafeHandleStream(THandleStream * Source, bool Own) :
+  THandleStream(Source->Handle)
+{
+  FSource = Own ? Source : NULL;
+}
+//---------------------------------------------------------------------------
+TSafeHandleStream * TSafeHandleStream::CreateFromFile(const UnicodeString & FileName, unsigned short Mode)
+{
+  return new TSafeHandleStream(new TFileStream(ApiPath(FileName), Mode), true);
+}
+//---------------------------------------------------------------------------
+__fastcall TSafeHandleStream::~TSafeHandleStream()
+{
+  SAFE_DESTROY(FSource);
+}
+//---------------------------------------------------------------------------
 int __fastcall TSafeHandleStream::Read(void * Buffer, int Count)
 {
   int Result = FileRead(FHandle, Buffer, Count);
@@ -272,7 +289,7 @@ int __fastcall TSafeHandleStream::Write(const void * Buffer, int Count)
 //---------------------------------------------------------------------------
 int __fastcall TSafeHandleStream::Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count)
 {
-  DebugFail(); // untested
+  // This is invoked for example via CopyFrom from TParallelOperation::Done
   int Result = FileRead(FHandle, Buffer, Offset, Count);
   if (Result == -1)
   {
@@ -283,7 +300,7 @@ int __fastcall TSafeHandleStream::Read(System::DynamicArray<System::Byte> Buffer
 //---------------------------------------------------------------------------
 int __fastcall TSafeHandleStream::Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count)
 {
-  // This is invoked for example by TIniFileStorage::Flush
+  // This is invoked for example by TIniFileStorage::Flush or via CopyFrom from TParallelOperation::Done
   int Result = FileWrite(FHandle, Buffer, Offset, Count);
   if (Result == -1)
   {

+ 6 - 0
source/core/FileBuffer.h

@@ -49,10 +49,16 @@ class TSafeHandleStream : public THandleStream
 {
 public:
   __fastcall TSafeHandleStream(int AHandle);
+  __fastcall TSafeHandleStream(THandleStream * Source, bool Own);
+  static TSafeHandleStream * CreateFromFile(const UnicodeString & FileName, unsigned short Mode);
+  virtual __fastcall ~TSafeHandleStream();
   virtual int __fastcall Read(void * Buffer, int Count);
   virtual int __fastcall Write(const void * Buffer, int Count);
   virtual int __fastcall Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
   virtual int __fastcall Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
+private:
+  THandleStream * FSource;
+  bool FOwned;
 };
 //---------------------------------------------------------------------------
 char * __fastcall EOLToStr(TEOLType EOLType);

+ 2 - 2
source/core/Terminal.cpp

@@ -915,8 +915,8 @@ void TParallelOperation::Done(
                     {
                       {
                         Terminal->LogEvent(FORMAT(L"Appending part %d of \"%s\" to \"%s\"...", (Index, FileNameOnly, TargetNamePartialOnly)));
-                        std::unique_ptr<TFileStream> SourceStream(new TFileStream(ApiPath(TargetPartName), fmOpenRead | fmShareDenyWrite));
-                        std::unique_ptr<TFileStream> DestStream(new TFileStream(ApiPath(TargetNamePartial), fmOpenWrite | fmShareDenyWrite));
+                        std::unique_ptr<THandleStream> SourceStream(TSafeHandleStream::CreateFromFile(TargetPartName, fmOpenRead | fmShareDenyWrite));
+                        std::unique_ptr<THandleStream> DestStream(TSafeHandleStream::CreateFromFile(TargetNamePartial, fmOpenWrite | fmShareDenyWrite));
                         HANDLE DestHandle = reinterpret_cast<HANDLE>(DestStream->Handle);
                         FILETIME WrTime;
                         bool GotWrTime = GetFileTime(DestHandle, NULL, NULL, &WrTime);