This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup] Query the user if a corrupt local file is found


If a corrupt file is found in one of the selected mirror site
directories, offer to delete it instead of making this a fatal error.
Do this only on the first call to check_for cached().  If the corrupt
file is still there on the second call, then the deletion failed, and
the user will have to fix the problem.

See https://cygwin.com/ml/cygwin/2017-12/msg00122.html for discussion.
---
 download.cc | 17 ++++++++++++-----
 download.h  |  4 +++-
 res.rc      |  3 ++-
 resource.h  |  1 +
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/download.cc b/download.cc
index b606eb1..697f94a 100644
--- a/download.cc
+++ b/download.cc
@@ -71,7 +71,7 @@ validateCachedPackage (const std::string& fullname, packagesource & pkgsource)
 /* 0 on failure
  */
 int
-check_for_cached (packagesource & pkgsource, bool mirror_mode)
+check_for_cached (packagesource & pkgsource, bool mirror_mode, bool query_corrupt, HWND owner)
 {
   // Already found one.
   if (pkgsource.Cached())
@@ -114,6 +114,12 @@ check_for_cached (packagesource & pkgsource, bool mirror_mode)
     {
       if (validateCachedPackage (fullname, pkgsource))
         pkgsource.set_cached (fullname);
+      else if (query_corrupt && owner && !unattended_mode
+	       && yesno (owner, IDS_QUERY_CORRUPT, fullname.c_str()) == IDYES)
+	{
+	  io_stream::remove (fullname);
+	  continue;
+	}
       else
         throw new Exception (TOSTRING(__LINE__) " " __FILE__,
             "Package validation failure for " + fullname,
@@ -266,13 +272,14 @@ do_download_thread (HINSTANCE h, HWND owner)
 	    {
 	      if (pkg.picked())
 		{
-		    if (!check_for_cached (*version.source()))
-		      total_download_bytes += version.source()->size;
+		  if (!check_for_cached (*version.source(), false, true, owner))
+		    total_download_bytes += version.source()->size;
 		}
 	      if (pkg.srcpicked () || IncludeSource)
 		{
-		    if (!check_for_cached (*sourceversion.source()))
-		      total_download_bytes += sourceversion.source()->size;
+		  if (!check_for_cached (*sourceversion.source(), false,
+					 true, owner))
+		    total_download_bytes += sourceversion.source()->size;
 		}
 	    }
 	  catch (Exception * e)
diff --git a/download.h b/download.h
index 117a44d..e9eb257 100644
--- a/download.h
+++ b/download.h
@@ -16,7 +16,9 @@
 #ifndef SETUP_DOWNLOAD_H
 #define SETUP_DOWNLOAD_H
 
+#include "win32.h"
+
 class packagesource;
-int check_for_cached (packagesource & pkgsource, bool = false);
+int check_for_cached (packagesource & pkgsource, bool mirror_mode = false, bool query_corrupt = false, HWND owner = NULL);
 
 #endif /* SETUP_DOWNLOAD_H */
diff --git a/res.rc b/res.rc
index 901cf76..31c8f20 100644
--- a/res.rc
+++ b/res.rc
@@ -550,7 +550,8 @@ BEGIN
     IDS_DOWNLOAD_INCOMPLETE_EXIT  "Download incomplete.  Check %s for details"
     IDS_INSTALL_ERROR	    "Installation error (%s), Continue with other packages?"
     IDS_INSTALL_INCOMPLETE  "Installation incomplete.  Check %s for details"
-    IDS_CORRUPT_PACKAGE     "Package file %s has a corrupt local copy, please remove and retry."
+    IDS_CORRUPT_PACKAGE     "Package %s has a corrupt local copy, please remove and retry."
+    IDS_QUERY_CORRUPT       "The file %s is corrupt.  Delete it?."
     IDS_SKIP_PACKAGE	    "%s\nDo you want to skip this package ?"
     IDS_UNCAUGHT_EXCEPTION  "Fatal Error: Uncaught Exception\nThread: %s\nType: %s\nMessage: %s"
     IDS_UNCAUGHT_EXCEPTION_WITH_ERRNO  "Fatal Error: Uncaught Exception\nThread: %s\nType: %s\nMessage: %s\nAppErrNo: %d"
diff --git a/resource.h b/resource.h
index 79b876d..70d90ca 100644
--- a/resource.h
+++ b/resource.h
@@ -39,6 +39,7 @@
 #define IDS_ELEVATED			  139
 #define IDS_INSTALLEDB_VERSION            140
 #define IDS_DOWNLOAD_INCOMPLETE_EXIT      141
+#define IDS_QUERY_CORRUPT                 142
 
 // Dialogs
 
-- 
2.15.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]