For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > October 2007 > Using rename() across file systems









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using rename() across file systems
J de Boyne Pollard

2007-10-26, 7:11 pm

JHT> I am working on an application that can transfer a file
JHT> over a potentially slow link and, when the transfer has
JHT> successfully completed, copies the file from a
JHT> temporary file that was created for this purpose to its
JHT> final destination. I am using the rename() function to
JHT> do this final step.

That's a move, not a copy.

JHT> I have read in "Advanced Unix Programming" by Marc
JHT> Rochkind that rename will not work if the source and
JHT> destination reside on different file systems. [...]
JHT> [...] my intention is to have my own function detect
JHT> this by calling statvfs() for the source name and the
JHT> name of the parent in the destination and comparing
JHT> the f_fsid member of the resulting structures. [...]

Why make life so hard for yourself? Put the temporary file in the
same directory as the final location, and stop worrying about
different filesystems. If renaming a file from one name to another
within a single directory would cross filesystems, then you are
probably using something very unusual (such as stacked filesystems)
and as such probably have other, more serious, design issues to
contend with first. (-:

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com