Pārlūkot izejas kodu

Refactoring some exceptions, mainly EScpSkipFile

Source commit: 557cfaff84d1f003c85cd00dc3a7d4d34e82a02d
Martin Prikryl 7 gadi atpakaļ
vecāks
revīzija
cdfc79a41c

+ 16 - 6
source/core/Exceptions.h

@@ -69,9 +69,7 @@ private:
   UnicodeString FHelpKeyword;
 };
 //---------------------------------------------------------------------------
-#define DERIVE_EXT_EXCEPTION(NAME, BASE) \
-  class NAME : public BASE \
-  { \
+#define EXT_EXCEPTION_METHODS(NAME, BASE) \
   public: \
     inline __fastcall NAME(Exception* E, UnicodeString Msg, UnicodeString HelpKeyword = L"") : \
       BASE(E, Msg, HelpKeyword) \
@@ -115,15 +113,27 @@ private:
     virtual void __fastcall Rethrow() \
     { \
       throw NAME(this, L""); \
-    } \
+    }
+
+#define DERIVE_EXT_EXCEPTION(NAME, BASE) \
+  class NAME : public BASE \
+  { \
+    EXT_EXCEPTION_METHODS(NAME, BASE) \
   };
 //---------------------------------------------------------------------------
 DERIVE_EXT_EXCEPTION(ESsh, ExtException);
 DERIVE_EXT_EXCEPTION(ETerminal, ExtException);
 DERIVE_EXT_EXCEPTION(ECommand, ExtException);
 DERIVE_EXT_EXCEPTION(EScp, ExtException); // SCP protocol fatal error (non-fatal in application context)
-DERIVE_EXT_EXCEPTION(EScpSkipFile, ExtException);
-DERIVE_EXT_EXCEPTION(EScpFileSkipped, EScpSkipFile);
+class ESkipFile : public ExtException
+{
+public:
+  inline __fastcall ESkipFile() :
+    ExtException(NULL, UnicodeString())
+  {
+  }
+  EXT_EXCEPTION_METHODS(ESkipFile, ExtException)
+};
 //---------------------------------------------------------------------------
 class EOSExtException : public ExtException
 {

+ 1 - 1
source/core/FtpFileSystem.cpp

@@ -1498,7 +1498,7 @@ void __fastcall TFTPFileSystem::FileTransfer(const UnicodeString & FileName,
   switch (FFileTransferAbort)
   {
     case ftaSkip:
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
 
     case ftaCancel:
       Abort();

+ 3 - 3
source/core/S3FileSystem.cpp

@@ -1122,7 +1122,7 @@ void TS3FileSystem::ConfirmOverwrite(
       break;
 
     case qaNo:
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
 
     default:
       DebugFail();
@@ -1156,7 +1156,7 @@ int TS3FileSystem::PutObjectData(int BufferSize, char * Buffer, TLibS3PutObjectD
   TFileOperationProgressType * OperationProgress = Data.OperationProgress;
   if (OperationProgress->Cancel != csContinue)
   {
-    Data.Exception.reset(new EAbort(L""));
+      Data.Exception.reset(new EAbort(L""));
     Result = -1;
   }
   else
@@ -1519,7 +1519,7 @@ void __fastcall TS3FileSystem::Sink(
     HANDLE LocalHandle;
     if (!FTerminal->CreateLocalFile(DestFullName, OperationProgress, &LocalHandle, FLAGSET(Params, cpNoConfirmation)))
     {
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
     }
 
     std::unique_ptr<TStream> Stream(new TSafeHandleStream(reinterpret_cast<THandle>(LocalHandle)));

+ 13 - 17
source/core/ScpFileSystem.cpp

@@ -31,11 +31,7 @@ const int ecIgnoreWarnings = 2;
 const int ecReadProgress = 4;
 const int ecDefault = ecRaiseExcept;
 //---------------------------------------------------------------------------
-#define THROW_FILE_SKIPPED(EXCEPTION, MESSAGE) \
-  throw EScpFileSkipped(EXCEPTION, MESSAGE)
-
-#define THROW_SCP_ERROR(EXCEPTION, MESSAGE) \
-  throw EScp(EXCEPTION, MESSAGE)
+DERIVE_EXT_EXCEPTION(EScpFileSkipped, ESkipFile);
 //===========================================================================
 #define MaxShellCommand fsLang
 #define ShellCommandCount MaxShellCommand + 1
@@ -1465,11 +1461,11 @@ void __fastcall TSCPFileSystem::SCPResponse(bool * GotLastLine)
 
       if (Resp == 1)
       {
-        THROW_FILE_SKIPPED(NULL, Msg);
+        throw EScpFileSkipped(NULL, Msg);
       }
       else
       {
-        THROW_SCP_ERROR(NULL, Msg);
+        throw EScp(NULL, Msg);
       }
   }
 }
@@ -1636,7 +1632,7 @@ void __fastcall TSCPFileSystem::CopyToRemote(TStrings * FilesToCopy,
             throw;
           }
         }
-        catch (EScpSkipFile &E)
+        catch (ESkipFile &E)
         {
           OperationProgress->Finish(FileName, false, OnceDoneOperation);
 
@@ -1714,7 +1710,7 @@ void __fastcall TSCPFileSystem::SCPSource(const UnicodeString FileName,
 
   if (!FTerminal->AllowLocalFileTransfer(FileName, CopyParam, OperationProgress))
   {
-    THROW_SKIP_FILE_NULL;
+    throw ESkipFile();
   }
 
   TLocalFileHandle Handle;
@@ -1916,7 +1912,7 @@ void __fastcall TSCPFileSystem::SCPSource(const UnicodeString FileName,
     }
     catch (Exception &E)
     {
-      // EScpFileSkipped is derived from EScpSkipFile,
+      // EScpFileSkipped is derived from ESkipFile,
       // but is does not indicate file skipped by user here
       if (dynamic_cast<EScpFileSkipped *>(&E) != NULL)
       {
@@ -2022,8 +2018,8 @@ void __fastcall TSCPFileSystem::SCPDirectorySource(const UnicodeString Directory
             SCPSource(FileName, TargetDirFull, CopyParam, Params, OperationProgress, Level + 1);
           }
         }
-        // Previously we caught EScpSkipFile, making error being displayed
-        // even when file was excluded by mask. Now the EScpSkipFile is special
+        // Previously we caught ESkipFile, making error being displayed
+        // even when file was excluded by mask. Now the ESkipFile is special
         // case without error message.
         catch (EScpFileSkipped &E)
         {
@@ -2040,7 +2036,7 @@ void __fastcall TSCPFileSystem::SCPDirectorySource(const UnicodeString Directory
             throw;
           }
         }
-        catch (EScpSkipFile &E)
+        catch (ESkipFile &E)
         {
           // If ESkipFile occurs, just log it and continue with next file
           TSuspendFileOperationProgress Suspend(OperationProgress);
@@ -2230,7 +2226,7 @@ void __fastcall TSCPFileSystem::Sink(
 void __fastcall TSCPFileSystem::SCPError(const UnicodeString Message, bool Fatal)
 {
   SCPSendError(Message, Fatal);
-  THROW_FILE_SKIPPED(NULL, Message);
+  throw EScpFileSkipped(NULL, Message);
 }
 //---------------------------------------------------------------------------
 void __fastcall TSCPFileSystem::SCPSendError(const UnicodeString Message, bool Fatal)
@@ -2327,7 +2323,7 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
         switch (Ctrl) {
           case 1:
             // Error (already logged by ReceiveLine())
-            THROW_FILE_SKIPPED(NULL, FMTLOAD(REMOTE_ERROR, (Line)));
+            throw EScpFileSkipped(NULL, FMTLOAD(REMOTE_ERROR, (Line)));
 
           case 2:
             // Fatal error, terminate copying
@@ -2395,7 +2391,7 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
         // last possibility to cancel transfer before it starts
         if (OperationProgress->Cancel)
         {
-          THROW_SKIP_FILE(NULL, MainInstructions(LoadStr(USER_TERMINATED)));
+          throw ESkipFile(NULL, MainInstructions(LoadStr(USER_TERMINATED)));
         }
 
         bool Dir = (Ctrl == L'D');
@@ -2647,7 +2643,7 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
       // successful, even when for example user refused to overwrite file
       Success = false;
     }
-    catch (EScpSkipFile &E)
+    catch (ESkipFile &E)
     {
       SCPSendError(E.Message, false);
       Success = false;

+ 4 - 4
source/core/SftpFileSystem.cpp

@@ -4359,7 +4359,7 @@ void __fastcall TSFTPFileSystem::SFTPConfirmOverwrite(
         break;
 
       case qaNo:
-        THROW_SKIP_FILE_NULL;
+        throw ESkipFile();
     }
   }
 }
@@ -4657,7 +4657,7 @@ void __fastcall TSFTPFileSystem::Source(
         {
           if (OperationProgress->ClearCancelFile())
           {
-            THROW_SKIP_FILE_NULL;
+            throw ESkipFile();
           }
           else
           {
@@ -5314,7 +5314,7 @@ void __fastcall TSFTPFileSystem::Sink(
       if (!FTerminal->CreateLocalFile(LocalFileName, OperationProgress,
              &LocalHandle, FLAGSET(Params, cpNoConfirmation)))
       {
-        THROW_SKIP_FILE_NULL;
+        throw ESkipFile();
       }
     }
     DebugAssert(LocalHandle);
@@ -5451,7 +5451,7 @@ void __fastcall TSFTPFileSystem::Sink(
           {
             if (OperationProgress->ClearCancelFile())
             {
-              THROW_SKIP_FILE_NULL;
+              throw ESkipFile();
             }
             else
             {

+ 18 - 18
source/core/Terminal.cpp

@@ -2254,7 +2254,7 @@ bool __fastcall TTerminal::FileOperationLoopQuery(Exception & E,
 
     if (AllowSkip)
     {
-      THROW_SKIP_FILE(&E, Message);
+      throw ESkipFile(&E, Message);
     }
     else
     {
@@ -2271,8 +2271,8 @@ void __fastcall TTerminal::FileOperationLoopEnd(Exception & E,
   unsigned int Flags, const UnicodeString & SpecialRetry, const UnicodeString & HelpKeyword)
 {
   if ((dynamic_cast<EAbort *>(&E) != NULL) ||
-      (dynamic_cast<EScpSkipFile *>(&E) != NULL) ||
-      (dynamic_cast<EScpSkipFile *>(&E) != NULL))
+      (dynamic_cast<ESkipFile *>(&E) != NULL) ||
+      (dynamic_cast<ESkipFile *>(&E) != NULL))
   {
     RethrowException(&E);
   }
@@ -3165,11 +3165,11 @@ void __fastcall inline TTerminal::LogEvent(const UnicodeString & Str)
 void __fastcall TTerminal::RollbackAction(TSessionAction & Action,
   TFileOperationProgressType * OperationProgress, Exception * E)
 {
-  // EScpSkipFile without "cancel" is file skip,
+  // ESkipFile without "cancel" is file skip,
   // and we do not want to record skipped actions.
-  // But EScpSkipFile with "cancel" is abort and we want to record that.
+  // But ESkipFile with "cancel" is abort and we want to record that.
   // Note that TSCPFileSystem modifies the logic of RollbackAction little bit.
-  if ((dynamic_cast<EScpSkipFile *>(E) != NULL) &&
+  if ((dynamic_cast<ESkipFile *>(E) != NULL) &&
       ((OperationProgress == NULL) ||
        (OperationProgress->Cancel == csContinue)))
   {
@@ -3623,8 +3623,8 @@ void __fastcall TTerminal::ProcessDirectory(const UnicodeString DirName,
         if (!File->IsParentDirectory && !File->IsThisDirectory)
         {
           CallBackFunc(Directory + File->FileName, File, Param);
-          // We should catch EScpSkipFile here as we do in ProcessFiles.
-          // Now we have to handle EScpSkipFile in every callback implementation.
+          // We should catch ESkipFile here as we do in ProcessFiles.
+          // Now we have to handle ESkipFile in every callback implementation.
         }
       }
     }
@@ -3781,7 +3781,7 @@ bool __fastcall TTerminal::ProcessFiles(TStrings * FileList,
               Progress.Finish(FileName, Success, OnceDoneOperation);
             }
           }
-          catch(EScpSkipFile & E)
+          catch(ESkipFile & E)
           {
             TSuspendFileOperationProgress Suspend(OperationProgress);
             if (!HandleException(&E))
@@ -5632,7 +5632,7 @@ void __fastcall TTerminal::SynchronizeCollectFile(const UnicodeString FileName,
   {
     DoSynchronizeCollectFile(FileName, File, Param);
   }
-  catch(EScpSkipFile & E)
+  catch(ESkipFile & E)
   {
     TSuspendFileOperationProgress Suspend(OperationProgress);
     if (!HandleException(&E))
@@ -6619,7 +6619,7 @@ void __fastcall TTerminal::DoCopyToRemote(
         SourceRobust(FileName, FullTargetDir, CopyParam, Params, OperationProgress, Flags | tfFirstLevel);
         Success = true;
       }
-      catch (EScpSkipFile & E)
+      catch (ESkipFile & E)
       {
         TSuspendFileOperationProgress Suspend(OperationProgress);
         if (!HandleException(&E))
@@ -6741,7 +6741,7 @@ void __fastcall TTerminal::DirectorySource(
             PostCreateDir = false;
           }
         }
-        catch (EScpSkipFile &E)
+        catch (ESkipFile &E)
         {
           // If ESkipFile occurs, just log it and continue with next file
           TSuspendFileOperationProgress Suspend(OperationProgress);
@@ -6868,7 +6868,7 @@ void __fastcall TTerminal::Source(
 
   if (!AllowLocalFileTransfer(FileName, CopyParam, OperationProgress))
   {
-    THROW_SKIP_FILE_NULL;
+    throw ESkipFile();
   }
 
   TLocalFileHandle Handle;
@@ -7076,7 +7076,7 @@ void __fastcall TTerminal::DoCopyToLocal(
         SinkRobust(AbsoluteFileName, File, FullTargetDir, CopyParam, Params, OperationProgress, Flags | tfFirstLevel);
         Success = true;
       }
-      catch (EScpSkipFile & E)
+      catch (ESkipFile & E)
       {
         TSuspendFileOperationProgress Suspend(OperationProgress);
         if (!HandleException(&E))
@@ -7162,13 +7162,13 @@ void __fastcall TTerminal::Sink(
   if (!CopyParam->AllowTransfer(BaseFileName, osRemote, File->IsDirectory, MaskParams))
   {
     LogEvent(FORMAT(L"File \"%s\" excluded from transfer", (FileName)));
-    THROW_SKIP_FILE_NULL;
+    throw ESkipFile();
   }
 
   if (CopyParam->SkipTransfer(FileName, File->IsDirectory))
   {
     OperationProgress->AddSkippedFileSize(File->Size);
-    THROW_SKIP_FILE_NULL;
+    throw ESkipFile();
   }
 
   LogFileDetails(FileName, File->Modification, File->Size);
@@ -7219,7 +7219,7 @@ void __fastcall TTerminal::Sink(
         // of any parent directory
         if (FLAGSET(Params, cpDelete) && SinkFileParams.Skipped)
         {
-          THROW_SKIP_FILE_NULL;
+          throw ESkipFile();
         }
       }
     }
@@ -7308,7 +7308,7 @@ void __fastcall TTerminal::SinkFile(UnicodeString FileName, const TRemoteFile *
     SinkRobust(FileName, File, Params->TargetDir, Params->CopyParam,
       Params->Params, Params->OperationProgress, Params->Flags);
   }
-  catch (EScpSkipFile & E)
+  catch (ESkipFile & E)
   {
     Params->Skipped = true;
 

+ 0 - 4
source/core/Terminal.h

@@ -64,10 +64,6 @@ typedef void __fastcall (__closure *TInformationEvent)
 typedef void __fastcall (__closure *TCustomCommandEvent)
   (TTerminal * Terminal, const UnicodeString & Command, bool & Handled);
 //---------------------------------------------------------------------------
-#define THROW_SKIP_FILE(EXCEPTION, MESSAGE) \
-  throw EScpSkipFile(EXCEPTION, MESSAGE)
-#define THROW_SKIP_FILE_NULL THROW_SKIP_FILE(NULL, L"")
-//---------------------------------------------------------------------------
 const unsigned int folNone = 0x00;
 const unsigned int folAllowSkip = 0x01;
 const unsigned int folRetryOnFatal = 0x02;

+ 5 - 5
source/core/WebDAVFileSystem.cpp

@@ -631,7 +631,7 @@ void __fastcall TWebDAVFileSystem::CheckStatus(int NeonStatus)
     {
       DebugAssert(FSkipped);
       FSkipped = false;
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
     }
   }
   else
@@ -1125,7 +1125,7 @@ void __fastcall TWebDAVFileSystem::ConfirmOverwrite(
       break;
 
     case qaNo:
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
 
     default:
       DebugFail();
@@ -1290,7 +1290,7 @@ void __fastcall TWebDAVFileSystem::Source(
       FD = _open_osfhandle((intptr_t)Handle.Handle, O_BINARY);
       if (FD < 0)
       {
-        THROW_SKIP_FILE_NULL;
+        throw ESkipFile();
       }
 
       TAutoFlag UploadingFlag(FUploading);
@@ -1675,7 +1675,7 @@ void __fastcall TWebDAVFileSystem::Sink(
     HANDLE LocalHandle;
     if (!FTerminal->CreateLocalFile(DestFullName, OperationProgress, &LocalHandle, FLAGSET(Params, cpNoConfirmation)))
     {
-      THROW_SKIP_FILE_NULL;
+      throw ESkipFile();
     }
 
     bool DeleteLocalFile = true;
@@ -1686,7 +1686,7 @@ void __fastcall TWebDAVFileSystem::Sink(
       FD = _open_osfhandle((intptr_t)LocalHandle, O_BINARY);
       if (FD < 0)
       {
-        THROW_SKIP_FILE_NULL;
+        throw ESkipFile();
       }
 
       TAutoFlag DownloadingFlag(FDownloading);