"what actually does unlink do?"

The post by Eliya is very close to the mark. Since we are talking about "unlink", another point is of interest especially if you are ever writing a program that updates software.

This discussion applies to Windows also! A "file" is a collection of data bits on the disk. The directory has a "human readable name" that "points" to those bits. The "open" translates the "human readable name" into a data structure that the file system uses to access the data bits, this is the "filehandle". Once a file is "open", the "name" doesn't matter <- this is important. If the file is open, you can change the name or even delete the name without affecting the data bits!

Its been a while since I wrote a software updater for a continuously running system, but basically the idea is to copy all the important stuff onto the target. Say x.dll would get a temporary name of x_temp.dll. Then, x.dll gets "unlinked". Everyone who has this file "open" and is using it, continues to use it even though it has no "name". Then, x_temp.dll is renamed to x.dll and new requests for "x.dll" will get the updated file. The actual "old x.dll" file bits will get "deleted" when then are no longer in use (everyone using it does a close). "Delete" in this case means to mark that area of the disk as available for other use.

From say the Windows command line, you might see something like >del X, unable to delete file X, file is in use. However the Perl unlink 'X' command will succeed.

the above was just to round out discussion of "what does unlink" do - and it is a bit different than command line "delete". Sounds to me like the most likely thing in OP's scenario is wrong permissions on the directory. Unlink of a read only file is completely ok. Anyway, Perl "unlink" does what a UNIX person would expect, even on Windows.


In reply to Re^3: Deleting or unlinking a file by Marshall
in thread Deleting or unlinking a file by Anonymous Monk

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.