Skip to content

Commit

Permalink
Fixed test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 2, 2013
1 parent 9548614 commit 8d180e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,12 @@ public boolean renameTo(final FileResource<?> target)

private boolean renameTo(final File target)
{
try
if (getFileOperations().renameFile(file, target))
{
getFileOperations().moveFile(file, target);
file = target;
return true;
}
catch (IOException e)
{
throw new ResourceException(e);
}
return false;
}

@Override
Expand Down Expand Up @@ -525,20 +521,8 @@ public InputStream createInputStream(File file) throws IOException
return new BufferedInputStream(new FileInputStream(file));
}

/**
* Moves a file.
* <p>
* When the destination file is on another file system, do a "copy and delete".
*
* @param srcFile the file to be moved
* @param destFile the destination file
* @throws NullPointerException if source or destination is <code>null</code>
* @throws IOException if s /** The number of bytes in a kilobyte.
* @throws IOException if an IO error occurs moving the file
* @since Commons IO 1.4
*/
@Override
public void moveFile(File srcFile, File destFile) throws IOException
public boolean renameFile(File srcFile, File destFile)
{
if (srcFile == null)
{
Expand All @@ -548,33 +532,7 @@ public void moveFile(File srcFile, File destFile) throws IOException
{
throw new NullPointerException("Destination must not be null");
}
if (!srcFile.exists())
{
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
}
if (srcFile.isDirectory())
{
throw new IOException("Source '" + srcFile + "' is a directory");
}
if (destFile.exists())
{
throw new IOException("Destination '" + destFile + "' already exists");
}
if (destFile.isDirectory())
{
throw new IOException("Destination '" + destFile + "' is a directory");
}
boolean rename = srcFile.renameTo(destFile);
if (!rename)
{
copyFile(srcFile, destFile);
if (!srcFile.delete())
{
deleteFile(destFile);
throw new IOException("Failed to delete original file '" + srcFile +
"' after copy to '" + destFile + "'");
}
}
return srcFile.renameTo(destFile);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface FileResourceOperations

public long getFileLength(File file);

public void moveFile(File src, File dest) throws IOException;
public boolean renameFile(File src, File dest);

public void copyFile(File src, File dest) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,17 @@ public long getFileLength(File f)
}

@Override
public void moveFile(File src, File dest) throws IOException
public boolean renameFile(File src, File dest)
{
assertSessionCreated();
try
{
session.moveFile(src, dest);
return true;
}
catch (FileAlreadyExistsException fae)
{
return false;
}
catch (Exception e)
{
Expand Down

0 comments on commit 8d180e9

Please sign in to comment.