org.fcrepo.server.journal.helpers
Class FileMovingUtil

java.lang.Object
  extended by org.fcrepo.server.journal.helpers.FileMovingUtil

public class FileMovingUtil
extends Object

Provides a workaround to the fact that java.io.File.renameTo(java.io.File) doesn't work across NFS file systems.

This code is taken from a workaround provided on the Sun Developer Network Bug Database (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756), by mailto:morgan.sziraki@cartesian.co.uk

The code is modified to protect against a situation where

If we do a simple copy, we leave open the possibility that the second process will see the new file created before we have a chance to copy the contents.

To avoid this, we create the new file with a modified filename (prefixed by an underscore '_'). When the copying is complete, we rename the file to the desired name. This rename is within a directory, and therefore does not extend across NFS filesystem boundaries, so it should work!

Modify again to make sure that neither the destination file nor the temp file exist - throw an exception if they do. We can't rename on top of an existing file.

Author:
Jim Blake

Method Summary
static void move(File fromFile, File toFile)
           Move a File
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

move

public static final void move(File fromFile,
                              File toFile)
                       throws IOException

Move a File

The renameTo method does not allow action across NFS mounted filesystems. This method is the workaround.

Parameters:
fromFile - The existing File
toFile - The new File
Throws:
IOException - if any problems occur


Copyright © 2011 DuraSpace. All Rights Reserved.