[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nsis-commits
Subject:    [NSIS-commits] SF.net SVN: nsis: [5638]
From:       kichik () users ! sourceforge ! net
Date:       2008-05-10 10:42:25
Message-ID: E1JumX3-00086x-7r () sc8-pr-svn2 ! sourceforge ! net
[Download RAW message or body]

Revision: 5638
          http://nsis.svn.sourceforge.net/nsis/?rev=5638&view=rev
Author:   kichik
Date:     2008-05-10 03:42:24 -0700 (Sat, 10 May 2008)

Log Message:
-----------
fixed bug #1946112 - Wrong free space calculation

Modified Paths:
--------------
    NSIS/trunk/Source/exehead/Ui.c

Modified: NSIS/trunk/Source/exehead/Ui.c
===================================================================
--- NSIS/trunk/Source/exehead/Ui.c	2008-05-08 10:28:34 UTC (rev 5637)
+++ NSIS/trunk/Source/exehead/Ui.c	2008-05-10 10:42:24 UTC (rev 5638)
@@ -982,7 +982,7 @@
   if (uMsg == WM_IN_UPDATEMSG || uMsg == WM_NOTIFY_START)
   {
     static char s[NSIS_MAX_STRLEN];
-    char *p;
+    char *root;
     int error = 0;
     int available_set = 0;
     unsigned total, available = 0xFFFFFFFF;
@@ -991,10 +991,24 @@
     if (!is_valid_instpath(dir))
       error = NSIS_INSTDIR_INVALID;
 
+    /**
+     * This part is tricky. We need to make sure a few things:
+     *
+     *   1. GetDiskFreeSpaceEx is always called at least once for large HD.
+     *        Even if skip_root() returned NULL (e.g. "C:").
+     *        Note that trimslashtoend() will nullify "C:".
+     *   2. GetDiskFreeSpaceEx is called with the deepest valid directory.
+     *        e.g. C:\drive when the user types C:\drive\folder1\folder2.
+     *        This makes sure NTFS mount points are treated properly (#1946112).
+     *   3. `s' stays valid after the loop for GetDiskFreeSpace.
+     *        This means there is no cutting beyond what skip_root() returns.
+     *   4. If GetDiskFreeSpaceEx doesn't exist, GetDiskFreeSpace is used.
+     *   5. `dir' is never modified.
+     *
+     */
+
     mystrcpy(s,dir);
-    p=skip_root(s);
-    if (p)
-      *p=0;
+    root=skip_root(s);
 
     // Test for and use the GetDiskFreeSpaceEx API
     {
@@ -1004,22 +1018,38 @@
       {
         ULARGE_INTEGER available64;
         ULARGE_INTEGER a, b;
-        if (GDFSE(s, &available64, &a, &b))
+        char *p;
+        for (p = s; root != p; p = trimslashtoend(s))
         {
+          if (GDFSE(s, &available64, &a, &b))
+          {
 #ifndef _NSIS_NO_INT64_SHR
-          available = (int)(available64.QuadPart >> 10);
+            available = (int)(available64.QuadPart >> 10);
 #else
-          available = (int)(Int64ShrlMod32(available64.QuadPart, 10));
+            available = (int)(Int64ShrlMod32(available64.QuadPart, 10));
 #endif
-          available_set++;
+            available_set++;
+            break;
+          }
+
+          if (!root)
+          {
+            // don't call trimslashtoend() which will destroy the string
+            break;
+          }
         }
       }
     }
 
     if (!available_set)
     {
+      DWORD spc, bps, fc, tc;
+
+      // GetDiskFreeSpaceEx accepts any path, but GetDiskFreeSpace accepts only the \
root +      if (root)
+        *root=0;
+
       // GetDiskFreeSpaceEx is not available
-      DWORD spc, bps, fc, tc;
       if (GetDiskFreeSpace(s, &spc, &bps, &fc, &tc))
       {
         available = (int)MulDiv(bps * spc, fc, 1 << 10);


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
NSIS-commits mailing list
NSIS-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nsis-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic