// where we're mapping to is already linked somewhere else. Only case we support
// is where this is a remapping of the same file back to where it came from
if ( !from_file.equals( to_link )){
Logger.log(new LogAlert(download_manager, LogAlert.REPEATABLE, LogAlert.AT_ERROR,
"Attempt to link to existing link '" + existing_link.toString()
+ "'"));
return( false );
}
}
File existing_file = file_info.getFile( true );
if ( to_link.equals( existing_file )){
// already pointing to the right place
return( true );
}
for (int i=0;i<info.length;i++){
if ( to_link.equals( info[i].getFile( true ))){
Logger.log(new LogAlert(download_manager, LogAlert.REPEATABLE, LogAlert.AT_ERROR,
"Attempt to link to existing file '" + info[i].getFile(true)
+ "'"));
return( false );
}
}
if ( to_link.exists()){
if ( !existing_file.exists()){
// using a new file, make sure we recheck
download_manager.recheckFile( file_info );
}else{
if ( FileUtil.deleteWithRecycle(
existing_file,
download_manager.getDownloadState().getFlag( DownloadManagerState.FLAG_LOW_NOISE ))){
// new file, recheck
download_manager.recheckFile( file_info );
}else{
Logger.log(new LogAlert(download_manager, LogAlert.REPEATABLE, LogAlert.AT_ERROR,
"Failed to delete '" + existing_file.toString() + "'"));
return( false );
}
}
}else{
if ( existing_file.exists()){
if ( !FileUtil.renameFile( existing_file, to_link )){
Logger.log(new LogAlert(download_manager, LogAlert.REPEATABLE, LogAlert.AT_ERROR,
"Failed to rename '" + existing_file.toString() + "'" ));
return( false );
}
}