CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to know when a file is finished copying?

    I cannot imagine a real-life legitimate situation when someone may create a file with FILE_SHARE_WRITE access while performing a write operation into it. I truly can't think of a single one, can you?
    Seems we're digressed alot, but yes, I can imagine that several apps write to the same file "simultaneously", or better say, opened the same file for writing. This is only the matter of design, same as use exclusive access or not. The fact itself that such "shared write" access flag exists (and not only in Windows ) tells me that I'm not the only person who can imgine such situation.
    Best regards,
    Igor

  2. #17
    Join Date
    Apr 2009
    Posts
    598

    Re: How to know when a file is finished copying?

    Copy two files, instead of only one.

    When the second file arrives, you can presume the first file is finished copying, because files are copied sequentially, as far as I know on the systems I have used.

    You could also use a third file that would be sent first, and which would contain the size of your main file.

  3. #18
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: How to know when a file is finished copying?

    Quote Originally Posted by olivthill2 View Post
    ... because files are copied sequentially, as far as I know on the systems I have used.
    Why "sequentially"?
    What prevents OS to make a "parallel" copying?
    Victor Nijegorodov

  4. #19
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to know when a file is finished copying?

    Quote Originally Posted by olivthill2 View Post
    Copy two files, instead of only one.

    When the second file arrives, you can presume the first file is finished copying, because files are copied sequentially, as far as I know on the systems I have used.

    You could also use a third file that would be sent first, and which would contain the size of your main file.

    If the copying program copies one file, waits for it to complete then starts a 2nd file... Then sure.

    If you mark 2 files from explorer and make it copy them elsewhere. The order they start copying isn't defined, even the order they finish isn't defined, not even to be identical to the starting order. It may SEEM to be that way for you in the few tests you done, but it isn't guarantee to work that way. We had to explicitely move away from using SHFileOperation() in one project and write our own because we couldn't rely on internal ordering. If you have reparsepoints in your directory structure, you can get some really weird results.

  5. #20
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to know when a file is finished copying?

    Quote Originally Posted by ahmd View Post
    I cannot imagine a real-life legitimate situation when someone may create a file with FILE_SHARE_WRITE access while performing a write operation into it. I truly can't think of a single one, can you?
    Shared access databases ? I'm using them quite frequently. There is internal organisation to keep 2 treads/processes from putting the database or the indexes in a corrupt state ofc, that's why you still have file range locks to arrange something like that.

    Even without this. Windows itself is using this in the pagefile.

    Or if your program has a shared data segment (or shared filemapping which is basically the same).

    I have even seen video editing software that allows multiple authors to modify parts 'on the fly' while other users are watching.

  6. #21
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: How to know when a file is finished copying?

    Quote Originally Posted by Igor Vartanov View Post
    Seems we're digressed alot, but yes, I can imagine that several apps write to the same file "simultaneously", or better say, opened the same file for writing. .. The fact itself that such "shared write" access flag exists (and not only in Windows ) tells me that I'm not the only person who can imgine such situation
    OK you have a point. So, I guess, if they keep persistent handles to that file ... but that is clearly asking for trouble... Well, in that case one needs to use NT sys core APIs to determine if a file handle is still in use (my previous post). Again, we don't know the exact use the OP was intending for this. I just hope he doesn't use it to monitor database files.

    Quote Originally Posted by OReubens View Post
    Shared access databases ? I'm using them quite frequently. There is internal organisation to keep 2 treads/processes from putting the database or the indexes in a corrupt state ofc, that's why you still have file range locks to arrange something like that.

    Even without this. Windows itself is using this in the pagefile.

    Or if your program has a shared data segment (or shared filemapping which is basically the same).

    I have even seen video editing software that allows multiple authors to modify parts 'on the fly' while other users are watching.
    And you're sure that all that software opens files you mentioned with a FILE_SHARE_WRITE access while writing into it at the same time??? Please note that I'm not talking about FILE_SHARE_READ access mode, at which one can open a file being written to.

  7. #22
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to know when a file is finished copying?

    Quote Originally Posted by ahmd View Post
    And you're sure that all that software opens files you mentioned with a FILE_SHARE_WRITE access while writing into it at the same time??? Please note that I'm not talking about FILE_SHARE_READ access mode, at which one can open a file being written to.
    No. I'm actually sure that NOT all software opens files with share deny write and then writes to it.
    But you also can't say it has no use at all.

    Most database engines these days are services running on the machine where the database is stored, and all other processses that want to access the database send requests to that service (via a pipe or socket usually), so in this case, most databases will be exclusive access (by the service), but allow simultaneous access to the database via some API of the DB service. This is usually a more stable, reliable and more performant approach. But it does have the disadvantage that you need to install a database manager on the server, and that can be a complicated issue for small networks. Or for networks without a dedicated server.

    But the alternative is still possible. You can open a file and have 2 applications (or more) write to it at the same time, you'll need code to make sure your database and the indexes stay valid, but it can be done. Before high bandwidth networks (and dedicated servers) and fast CPU's became common place, this approach was quite common for ISAM based databases. With the move towards RDBMS databases, dedicated servers, faster networks, it's a bit of a dinosaur.

  8. #23
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to know when a file is finished copying?

    with a FILE_SHARE_WRITE access while writing into it at the same time???
    Just a little note: simultaneous opening file for writing is not equal to or stipulates simultaneous writing.
    Best regards,
    Igor

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured