w00t-labs / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
0 stars 0 forks source link

False sparse flag removal #619

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Using sparse allocating mode.
Try start download any file and immediately stop download ( Only one block 
should be written to disk).

What is the expected output? What do you see instead?
libtorrent trying to remove sparse flag (which cause increasing physical file 
allocation and time consumtion in DeviceIoControl(... FSCTL_SET_SPARSE). Sparse 
flag must be removed only if file fully allocated on disk.

What version of the product are you using? On what operating system?
trunk. Windows.

Please provide any additional information below.
attachment contains fix

Original issue reported on code.google.com by ajax16...@gmail.com on 10 May 2014 at 10:09

GoogleCodeExporter commented 9 years ago
Index: file.cpp
===================================================================
--- file.cpp    (revision 9845)
+++ file.cpp    (working copy)
@@ -1313,8 +1313,12 @@
            return true;
        }

-       // if we only have a single range in the file, we're not sparse
-       return returned_bytes != sizeof(FILE_ALLOCATED_RANGE_BUFFER);
+       // if we have more than one range in the file, we're sparse
+       if (returned_bytes != sizeof(FILE_ALLOCATED_RANGE_BUFFER)) {
+           return true;
+       }
+
+       return (in.Length.QuadPart != out[0].Length.QuadPart);
    }
 #endif

Original comment by ajax16...@gmail.com on 10 May 2014 at 10:10

GoogleCodeExporter commented 9 years ago
thanks! checked-in!

Original comment by arvid.no...@gmail.com on 10 May 2014 at 11:48