Jump to content

Atomic Move/Rename in Windows XP - is it possible?


Recommended Posts

i have a problem...

we're using Java to create a web page on the local hard drive of a WinXP Pro machine, and then in the same Java program, we're calling the "move output.htm doorentry.htm" command to effectively rename the file to what the browser sees.

The web page contains an automatic refresh every second, and is automatically regenerated by the Java every second, and we are doing the rename to stop the browser from reading a partially written-to file, but it doesn't seem to be having the desired effect.

it works for a few hours, but eventually the browser doesn't get all the content again, and as a result we get a blank page, and no refreshes. does anyone know how to get around this problem?

i basically need what we call in Linux an "atomic move" - so if the browser is reading from the file when it's overwritten, it doesn't read a partial file, it just reads the remainder of that inode string, and on the next read it goes down the new inode string.

I hope this makes sense...

Thanks in advance for any suggestions! :D

Link to comment
Share on other sites

Hi there, and Welcome.

I've been sitting here reading through your post, and have come to the conclusion that I do not have a clue to the solution to your problem, but I thought since you have been waiting a little while I would let you know somebody has at least read your post.

With specific problems on a Forum such as this it can take a while before someone comes along who has expertise in particular areas.

If the wait is too long and the problem still exists for you, I do have a couple of friends in Puerto Rico who deal with this sort of stuff all the time. I can put you in touch with them.

Hang on here for a while though, plenty of smart people about once they sign in.

Link to comment
Share on other sites

I also do not quite understand: is it the same application that does the refresh, as well as the rename? If so, why can it not coordinate these activities? If it is different applications, then they should also be able to communicate and coordinate their actions.

If I misunderstood your question, please clarify.

Link to comment
Share on other sites

I also do not quite understand: is it the same application that does the refresh, as well as the rename? If so, why can it not coordinate these activities? If it is different applications, then they should also be able to communicate and coordinate their actions.

If I misunderstood your question, please clarify.

OK, the HTML page contains an <meta refresh> tag, which, as i'm sure you know, tells the browser to just refresh. We have ours setup to tell the browser to refresh every second.

Oh, and we're using IE7 on Windows XP Pro SP2.

The application (and there is only one) is written in Java and generates the HTML page which the browser is displaying. This page gets regenerated every second as well (well, it's *slightly* longer than a second, because the Java has to do a split second's worth of processing first, so the refresh and regeneration do get out of sync very quickly).

So... to stop the browser trying to refresh at the same time as the Java is writing a new HTML file (and therefore displaying a corrupted, or empty, web page), we decided to get the Java to write to a tmp file, and then to move that tmp file over the top of the file shown in the browser, so when the browser next refreshes, it get the *whole* new file, instead of a partially written-to file.

In Linux, which is what i'm used to, this would work perfectly, because the move command in Linux ("mv") is atomic.

In Windows XP, however, the "move" command is not atomic, and so pretty soon after starting up this whole system, the browser reads a partial, or empty file, which doesn't contain the <meta refresh> and not only displays a blank page, but stops refreshing too!

If you are wondering what i mean by "atomic", the answer is that as far as the applications are concerned, the filename "display.htm" either points to this complete file, or that complete file. There is no in-between state.

In other words, the operating system, when it does it's "move" writes all of the data behind the first inode, and then performs the final inode switch to repoint the filename at the new data. That way, the applications never see an incomplete file because the filename is either pointing at the inodes for the old file, or the new file.

I hope this makes sense... i've been trying to find an explanation of "atomic" in this context on the web, but i can't...

Thanks again for any advice :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy