All of this is of course very application specific. But first, you should understand that once a file is open, the name in directory means NOTHING. Lets say that you have 5 programs that are reading file X at the moment. They all have their own file handle to that file - these processes use the file handle to talk to the file - NOT the name of the file.

Think of a file as a collection of bits on the disk. The directory provides a name that points to that set of bits. Update: small clarification: the "file name" only comes into play during "open()", once this "set of bits" on the disk is "open", the file name has no meaning at all.

Can I "unlink" a name to a collection of bits? Absolutely! That removes a name association to those collection of bits - it does not delete those bits. Will the file system keep this straight? Yes! (ok, not on DOS (Win98), but NTFS (Win NT+) and UNIX file systems can do this). Can I have a file handle open to a file "with no name", eg a file which has no directory entry? Yes!

Its been awhile since I wrote a Windows installation program, you may need to rename file X before you can unlink the name from the directory. Update: small clarification: Now you can copy in a new file "X". There will be a very small window where file "X" doesn't exist at all. Depending upon how this is done, it could just be some microseconds, but it could happen - just something to think about. If something only happens 10/million times, it will happen if the program is run enough million times!

So anyway in this case, say we wind up with 5 processes reading the "old file X". Remember that they aren't using the name "X", they are using a file handle to those bits that used to be called "X". Now we have a new file X. Every new program that starts and wants file X will get the new set of bits. But what about those other guys who have the old "stale" set of bits"? Well, they keep reading and using them until we say different. The file system will keep those "stale bits" in play until everybody using them "closes" the file.

This gets so messy with the Microsoft O/S that it generates lots of reboots because there is not such a big line between application and O/S.

So, Can I replace a read-only file with another? Yes! But you need a plan to tell the folks who were using the old version to read the file again.

I am not considering the case where multiple programs may be updating a file - that's way more complex. First let's get straight on the "hey, 5 people are reading a file and I want to give them a new file" case.


In reply to Re: How to identify a file is in readonly mode by Marshall
in thread How to identify a file is in readonly mode by srikrishnan

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.