The problem arises because NTFS preallocates the space for the whole file in one hit if it knows the final size, which it obviously does when using the CopyFile() API or an application that resolves to it. This is what allows the OS to report "There is not enough space on the disk." before it actually starts transfering data.

Perhaps the simplest way of determining when the copy is finished would be to loop over trying to open the file until you suceed. If the application doing the copying cooperates by opening it's output file with an exclusive lock, this will tell you when the file has been closed and the copy completed.

If the application doing the copying isn't being nice and opening the output file exclusively, then you could use the native API OpenFile (via Win32::API::Prototype or similar) to try and open the file OF_SHARE_EXCLUSIVE yourself. Once this succeeds, the copy has finished.

You might also try looking at the functions Win32::File to see if one of those will allow you to attempt an exclusive open of the file, but I've never managed to decypher what's going on in there -- the pod is scary:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: Those unreliable file stat operations in Win32 by BrowserUk
in thread Those unreliable file stat operations in Win32 by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.