Skip to content

Commit

Permalink
[XrdCl] Provide compatibility between root://localfile and file://.
Browse files Browse the repository at this point in the history
The 'root://localfile//path/filename.meta4' semantic is now deprecated,
and 'file://localhost/path/filename.meta4' instead!
This commit provides compatibility with the old method of accessing
local metalink files.
  • Loading branch information
simonmichal committed Jan 18, 2018
1 parent 3d9b327 commit f9edacf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/man/xrdcp.1
Expand Up @@ -438,7 +438,8 @@ Enable/Disable Metalink processing (enabled by default)

XRD_LOCALMETALINKFILE
.RS 5
Enable/Disable local Metalink file processing (by convention the following URL schema has to be used: root://localfile//path/filename.meta4)
Enable/Disable local Metalink file processing (by convention the following URL schema has to be used: root://localfile//path/filename.meta4)
The 'localfile' semantic is now deprecated, use file://localhost/path/filename.meta4 instead!
.RE

XRD_GLFNREDIRECTOR
Expand Down
2 changes: 1 addition & 1 deletion src/XrdCl/XrdClConstants.hh
Expand Up @@ -65,7 +65,7 @@ namespace XrdCl
const int DefaultMultiProtocol = 0;
const int DefaultParallelEvtLoop = 1;
const int DefaultMetalinkProcessing = 1;
const int DefaultLocalMetalinkFile = 1;
const int DefaultLocalMetalinkFile = 0;
const int DefaultXCpBlockSize = 134217728; // DefaultCPChunkSize * DefaultCPParallelChunks * 2
const int DefaultNoDelay = 1;
const int DefaultPreferIPv4 = 0;
Expand Down
37 changes: 34 additions & 3 deletions src/XrdCl/XrdClRedirectorRegistry.cc
Expand Up @@ -8,6 +8,9 @@
#include "XrdClRedirectorRegistry.hh"
#include "XrdCl/XrdClMetalinkRedirector.hh"
#include "XrdCl/XrdClPostMasterInterfaces.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdCl/XrdClLog.hh"

#include <arpa/inet.h>

Expand Down Expand Up @@ -36,8 +39,10 @@ RedirectorRegistry::~RedirectorRegistry()
delete itr->second.first;
}

XRootDStatus RedirectorRegistry::RegisterImpl( const URL &url, ResponseHandler *handler )
XRootDStatus RedirectorRegistry::RegisterImpl( const URL &u, ResponseHandler *handler )
{
URL url = ConvertLocalfile( u );

// we can only create a virtual redirector if
// a path to a metadata file has been provided
if( url.GetPath().empty() ) return XRootDStatus( stError, errNotSupported );
Expand Down Expand Up @@ -73,6 +78,28 @@ XRootDStatus RedirectorRegistry::RegisterImpl( const URL &url, ResponseHandler *
return XRootDStatus( stError, errNotSupported );
}

URL RedirectorRegistry::ConvertLocalfile( const URL &url )
{
int localml = DefaultLocalMetalinkFile;
DefaultEnv::GetEnv()->GetInt( "LocalMetalinkFile", localml );

if( localml && url.GetProtocol() == "root" && url.GetHostName() == "localfile" )
{
Log *log = DefaultEnv::GetLog();
log->Warning( PostMasterMsg,
"Please note that the 'root://localfile//path/filename.meta4' "
"semantic is now deprecated, use 'file://localhost/path/filename.meta4'"
"instead!" );

URL copy( url );
copy.SetHostName( "localhost" );
copy.SetProtocol( "file" );
return copy;
}

return url;
}

XRootDStatus RedirectorRegistry::Register( const URL &url )
{
return RegisterImpl( url, 0 );
Expand All @@ -86,8 +113,10 @@ XRootDStatus RedirectorRegistry::RegisterAndWait( const URL &url )
return MessageUtils::WaitForStatus( &handler );
}

VirtualRedirector* RedirectorRegistry::Get( const URL &url ) const
VirtualRedirector* RedirectorRegistry::Get( const URL &u ) const
{
URL url = ConvertLocalfile( u );

XrdSysMutexHelper scopedLock( pMutex );
// get the key and return the value if it is in the registry
// offset 24 is where the path has been stored
Expand All @@ -102,8 +131,10 @@ VirtualRedirector* RedirectorRegistry::Get( const URL &url ) const
//----------------------------------------------------------------------------
// Release the virtual redirector associated with the given URL
//----------------------------------------------------------------------------
void RedirectorRegistry::Release( const URL &url )
void RedirectorRegistry::Release( const URL &u )
{
URL url = ConvertLocalfile( u );

XrdSysMutexHelper scopedLock( pMutex );
// get the key and return the value if it is in the registry
// offset 24 is where the path has been stored
Expand Down
8 changes: 8 additions & 0 deletions src/XrdCl/XrdClRedirectorRegistry.hh
Expand Up @@ -147,6 +147,14 @@ class RedirectorRegistry
//----------------------------------------------------------------------------
XRootDStatus RegisterImpl( const URL &url, ResponseHandler *handler );

//----------------------------------------------------------------------------
//! Convert the old convention for accessing local metalink files:
//! root://localfile//path/metalink.meta4
//! into:
//! file://localhost/path/metalink.meta4
//----------------------------------------------------------------------------
static URL ConvertLocalfile( const URL &url );

//----------------------------------------------------------------------------
// Constructor (private!).
//----------------------------------------------------------------------------
Expand Down

0 comments on commit f9edacf

Please sign in to comment.