Hi,

Shaddy Baddah wrote:
Please find attached a patch to allow for override-able installation_root. I actually wrote this patch for release 1.7.0-52
Please find attached a revised patch that removes a system_printf() that I forgot to take out.

Regards,
Shaddy

diff -r b073827c578e -r 7754c52b6400 winsup/cygwin/include/cygwin/version.h
--- a/winsup/cygwin/include/cygwin/version.h    Mon Nov 23 14:53:41 2009 +1100
+++ b/winsup/cygwin/include/cygwin/version.h    Thu Nov 26 00:59:34 2009 +1100
@@ -413,6 +413,7 @@
 #define CYGWIN_INFO_CYGWIN_REGISTRY_NAME "Cygwin"
 #define CYGWIN_INFO_PROGRAM_OPTIONS_NAME "Program Options"
 #define CYGWIN_INFO_INSTALLATIONS_NAME   "Installations"
+#define CYGWIN_INFO_SETUP_NAME           "setup"
 
      /* The default cygdrive prefix. */
 
diff -r b073827c578e -r 7754c52b6400 winsup/cygwin/shared.cc
--- a/winsup/cygwin/shared.cc   Mon Nov 23 14:53:41 2009 +1100
+++ b/winsup/cygwin/shared.cc   Thu Nov 26 00:59:34 2009 +1100
@@ -91,16 +91,58 @@
   RtlInt64ToHexUnicodeString (hash_path_name (0, installation_root),
                              &installation_key, FALSE);
 
-  PWCHAR w = wcsrchr (installation_root, L'\\');
-  if (w)
+  reg_key setup_reg (true, KEY_READ, CYGWIN_INFO_SETUP_NAME, NULL);
+  WCHAR setup_installation_root[PATH_MAX];
+  if (setup_reg.get_int ("rootdir_is_installation_root", 0)
+      && (setup_reg.get_string ((const PWCHAR)L"rootdir",
+                               setup_installation_root, PATH_MAX,
+                               (const PWCHAR)L"") == ERROR_SUCCESS))
     {
+      DWORD attr = GetFileAttributesW(setup_installation_root);
+      if ((attr == INVALID_FILE_ATTRIBUTES)
+         || (! (attr & FILE_ATTRIBUTE_DIRECTORY)))
+       {
+         api_fatal ("Can't initialize Cygwin installation root dir.\n"
+                    "GetFileAttributesW(%p), %d",
+                    setup_installation_root, attr);
+       }
+      /* lop of any trailing slash, to be consistent with the dll handling */
+      size_t last_wchr_idx = wcslen(setup_installation_root) - 1;
+      if ((last_wchr_idx >= 0)
+         && (setup_installation_root[last_wchr_idx] == L'\\'))
+       setup_installation_root[last_wchr_idx] = L'\0';
+
+      wcscpy(installation_root, setup_installation_root);
+      p = installation_root;
+      if (wcsncmp (p, L"\\\\?\\", 4))  /* No long path prefix. */
+       {
+         if (!wcsncasecmp (p, L"\\\\", 2))     /* UNC */
+           {
+             p = wcpcpy (p, L"\\??\\UN");
+             wcsncat (p, setup_installation_root, PATH_MAX - 6);
+             *p = L'C';
+           }
+         else
+           {
+             p = wcpcpy (p, L"\\??\\");
+             wcsncat (p, setup_installation_root, PATH_MAX - 4);
+           }
+       }
+      installation_root[1] = L'?';
+    }
+  else
+    {
+      PWCHAR w = wcsrchr (installation_root, L'\\');
+      if (w)
+       {
+         *w = L'\0';
+         w = wcsrchr (installation_root, L'\\');
+       }
+      if (!w)
+       api_fatal ("Can't initialize Cygwin installation root dir.\n"
+                  "Invalid DLL path");
       *w = L'\0';
-      w = wcsrchr (installation_root, L'\\');
     }
-  if (!w)
-    api_fatal ("Can't initialize Cygwin installation root dir.\n"
-              "Invalid DLL path");
-  *w = L'\0';
 
   for (int i = 1; i >= 0; --i)
     {

Reply via email to