[tpm] Mysterious problem

Liam R E Quin liam at holoweb.net
Sat Jan 15 11:16:46 PST 2011


On Sat, 2011-01-15 at 13:29 -0500, arocker at Vex.Net wrote:


> I seem to have encountered a strange problem with Perl's "move"
> command (from File::Copy)
[...]

> If the file already exists in the destination directory, (a legitimate
> situation for this program), the original does not get deleted, but the
> move appears to have returned a "true" value. (I check it).

Looks to me like what is happening is the underlying system is
generating an error, but File::Copy doesn't handle system errors well.

The documentation says [[
    If possible, move() will simply rename the file.  Otherwise, it
    copies the file to the new location and deletes the original.  If
    an error occurs during this copy-and-delete process, you may be
    left with a (possibly partial) copy of the file under the
    destination name.
]]

If I'd written the interface it would for sure have returned an error if
an error was encountered!!! Given such sheer awfulness, I would be very
reluctant to trust File::Copy at all, but maybe that's just me :-)

You could try code that did,
   rename $oldname, $newname
and if that failed, used File::Copy's rmscopy (the name seems to be a
stupid pun on Richard Stallman and VMS),and, if that worked (use stat to
check file size and date maybe?) delete the original.

Be careful to avoid code like,

    if (! -d "$destination") {
      copy...
because something else could create the director between the test and
the call to copy (more likely than you might think, because pretty much
all multitasking operating systems treat I/O operations as possible
rescheduling opportunities...)

Hope this helps.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org



More information about the toronto-pm mailing list