Ver Fonte

Bug 1787: Better error message when writing INI file fails

https://winscp.net/tracker/1787

Source commit: 192462c771c854e83afb615f7379970d8a896c7e
Martin Prikryl há 6 anos atrás
pai
commit
1b196e756b
2 ficheiros alterados com 12 adições e 5 exclusões
  1. 1 1
      source/core/FileBuffer.cpp
  2. 11 4
      source/core/HierarchicalStorage.cpp

+ 1 - 1
source/core/FileBuffer.cpp

@@ -273,7 +273,7 @@ int __fastcall TSafeHandleStream::Read(System::DynamicArray<System::Byte> Buffer
 //---------------------------------------------------------------------------
 int __fastcall TSafeHandleStream::Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count)
 {
-  DebugFail(); // untested
+  // This is invoked for example by TIniFileStorage::Flush
   int Result = FileWrite(FHandle, Buffer, Offset, Count);
   if (Result == -1)
   {

+ 11 - 4
source/core/HierarchicalStorage.cpp

@@ -1593,14 +1593,21 @@ void __fastcall TIniFileStorage::Flush()
       }
       else
       {
-        std::unique_ptr<TStream> Stream(new THandleStream(int(Handle)));
         try
         {
-          Strings->SaveToStream(Stream.get());
+          std::unique_ptr<TStream> Stream(new TSafeHandleStream(int(Handle)));
+          try
+          {
+            Strings->SaveToStream(Stream.get());
+          }
+          __finally
+          {
+            CloseHandle(Handle);
+          }
         }
-        __finally
+        catch (Exception & E)
         {
-          CloseHandle(Handle);
+          throw ExtException(&E, FMTLOAD(WRITE_ERROR, (Storage)));
         }
       }
     }