Skip to content

Commit

Permalink
[XrdCl] xrdfs ls: add option to get checksum per entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Jan 12, 2021
1 parent 898f078 commit e2f697b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
4 changes: 3 additions & 1 deletion docs/man/xrdfs.1
Expand Up @@ -30,7 +30,7 @@ Modify permissions of the \fIpath\fR. Permission string example:
\fIrwxr-x--x\fR

.RE
\fBls\fR \fI[-l]\fR \fI[-u]\fR \fI[-R]\fR \fI[-D]\fR \fI[-Z]\fR \fI[dirname]\fR
\fBls\fR \fI[-l]\fR \fI[-u]\fR \fI[-R]\fR \fI[-D]\fR \fI[-Z]\fR \fI[-C]\fR \fI[dirname]\fR
.RS 3
Get directory listing.
.br
Expand All @@ -43,6 +43,8 @@ Get directory listing.
\fI-D\fR show duplicate entries
.br
\fI-Z\fR check if file is a ZIP archive and if yes list its content
.br
\fI-C\fR checksum every entry

.RE
\fBlocate\fR \fI[-n]\fR \fI[-r]\fR \fI[-d]\fR \fI[-m]\fR \fI[-i]\fR \fI[-p]\fR \fI<path>\fR
Expand Down
23 changes: 18 additions & 5 deletions src/XrdCl/XrdClFS.cc
Expand Up @@ -210,10 +210,10 @@ XRootDStatus DoCD( FileSystem *fs,
//------------------------------------------------------------------------------
// Helper function to calculate number of digits in a number
//------------------------------------------------------------------------------
int nbDigits( uint64_t nb )
uint32_t nbDigits( uint64_t nb )
{
if( nb == 0 ) return 1;
return int( log10( double(nb) ) + 1);
return uint32_t( log10( double(nb) ) + 1);
}

//------------------------------------------------------------------------------
Expand All @@ -230,6 +230,7 @@ XRootDStatus DoLS( FileSystem *fs,
uint32_t argc = args.size();
bool stats = false;
bool showUrls = false;
bool hascks = false;
std::string path;
DirListFlags::Flags flags = DirListFlags::Locate | DirListFlags::Merge;

Expand Down Expand Up @@ -262,6 +263,13 @@ XRootDStatus DoLS( FileSystem *fs,
// check if file is a ZIP archive if yes list content
flags |= DirListFlags::Zip;
}
else if( args[i] == "-C" )
{
// query checksum for each entry in the directory
hascks = true;
stats = true;
flags |= DirListFlags::Cksm;
}
else
path = args[i];
}
Expand Down Expand Up @@ -302,7 +310,7 @@ XRootDStatus DoLS( FileSystem *fs,
std::cerr << "incomplete." << std::endl;
}

uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0;
uint32_t ownerwidth = 0, groupwidth = 0, sizewidth = 0, ckswidth = 0;
DirectoryList::Iterator it;
for( it = list->Begin(); it != list->End() && stats; ++it )
{
Expand All @@ -313,6 +321,8 @@ XRootDStatus DoLS( FileSystem *fs,
groupwidth = info->GetGroup().size();
if( sizewidth < nbDigits( info->GetSize() ) )
sizewidth = nbDigits( info->GetSize() );
if( ckswidth < info->GetChecksum().size() )
ckswidth = info->GetChecksum().size();
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -340,6 +350,8 @@ XRootDStatus DoLS( FileSystem *fs,
std::cout << " " << std::setw( ownerwidth ) << info->GetOwner();
std::cout << " " << std::setw( groupwidth ) << info->GetGroup();
std::cout << " " << std::setw( sizewidth ) << info->GetSize();
if( info->HasChecksum() )
std::cout << " " << std::setw( sizewidth ) << info->GetChecksum();
std::cout << " " << info->GetModTimeAsString() << " ";
}
else
Expand Down Expand Up @@ -1776,13 +1788,14 @@ XRootDStatus PrintHelp( FileSystem *, Env *,
printf( " Modify permissions. Permission string example:\n" );
printf( " rwxr-x--x\n\n" );

printf( " ls [-l] [-u] [-R] [-D] [-Z] [dirname]\n" );
printf( " ls [-l] [-u] [-R] [-D] [-Z] [-C] [dirname]\n" );
printf( " Get directory listing.\n" );
printf( " -l stat every entry and pring long listing\n" );
printf( " -u print paths as URLs\n" );
printf( " -R list subdirectories recursively\n" );
printf( " -D show duplicate entries" );
printf( " -Z if a ZIP archive list its content\n\n" );
printf( " -Z if a ZIP archive list its content\n" );
printf( " -C checksum every entry\n\n" );

printf( " locate [-n] [-r] [-d] [-m] [-i] [-p] <path>\n" );
printf( " Get the locations of the path.\n" );
Expand Down
3 changes: 3 additions & 0 deletions src/XrdCl/XrdClFileSystem.cc
Expand Up @@ -1651,6 +1651,9 @@ namespace XrdCl
if( ( flags & DirListFlags::Stat ) || ( flags & DirListFlags::Recursive ) )
req->options[0] = kXR_dstat;

if( ( flags & DirListFlags::Cksm ) )
req->options[0] = kXR_dstat | kXR_dcksm;

if( flags & DirListFlags::Recursive )
handler = new RecursiveDirListHandler( *pImpl->pUrl, url.GetPath(), flags, handler, timeout );

Expand Down
3 changes: 2 additions & 1 deletion src/XrdCl/XrdClFileSystem.hh
Expand Up @@ -161,7 +161,8 @@ namespace XrdCl
Recursive = 4, //!< Do a recursive listing
Merge = 8, //!< Merge duplicates
Chunked = 16, //!< Serve chunked results for better performance
Zip = 32 //!< List content of ZIP files
Zip = 32, //!< List content of ZIP files
Cksm = 64 //!< Get checksum for every entry
};
};
XRDOUC_ENUM_OPERATORS( DirListFlags::Flags )
Expand Down
37 changes: 33 additions & 4 deletions src/XrdCl/XrdClXRootDResponses.cc
Expand Up @@ -109,9 +109,9 @@ namespace XrdCl
struct StatInfoImpl
{
StatInfoImpl() : pSize( 0 ), pFlags( 0 ), pModifyTime( 0 ),
pChangeTime( 0 ), pAccessTime( 0 ), pExtended( false )
pChangeTime( 0 ), pAccessTime( 0 ),
pExtended( false ), pHasCksum( false )
{

}

StatInfoImpl( const StatInfoImpl & pimpl ) : pId( pimpl.pId ),
Expand All @@ -123,7 +123,8 @@ namespace XrdCl
pMode( pimpl.pMode ),
pOwner( pimpl.pOwner ),
pGroup( pimpl.pGroup ),
pExtended( pimpl.pExtended )
pExtended( pimpl.pExtended ),
pHasCksum( pimpl.pHasCksum )
{
}

Expand Down Expand Up @@ -165,7 +166,7 @@ namespace XrdCl
return false;
}

if( chunks.size() == 9 )
if( chunks.size() >= 9 )
{
pChangeTime = ::strtoll( chunks[4].c_str(), &result, 0 );
if( *result != 0 )
Expand All @@ -191,6 +192,16 @@ namespace XrdCl
pExtended = true;
}

// after the extended stat information, we might have the checksum
if( chunks.size() >= 10 )
{
if( ( chunks[9] == "[" ) && ( chunks[11] == "]" ) )
{
pHasCksum = true;
pCksum = chunks[10];
}
}

return true;
}

Expand All @@ -205,6 +216,8 @@ namespace XrdCl
std::string pGroup;

bool pExtended;
bool pHasCksum;
std::string pCksum;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -390,6 +403,14 @@ namespace XrdCl
return pImpl->pGroup;
}

//------------------------------------------------------------------------
//! Get checksum
//------------------------------------------------------------------------
const std::string& StatInfo::GetChecksum() const
{
return pImpl->pCksum;
}

//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
Expand All @@ -398,6 +419,14 @@ namespace XrdCl
return pImpl->pExtended;
}

//------------------------------------------------------------------------
//! Has checksum
//------------------------------------------------------------------------
bool StatInfo::HasChecksum() const
{
return pImpl->pHasCksum;
}

//----------------------------------------------------------------------------
// StatInfo constructor
//----------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/XrdCl/XrdClXRootDResponses.hh
Expand Up @@ -512,16 +512,26 @@ namespace XrdCl
//------------------------------------------------------------------------
const std::string& GetGroup() const;

//------------------------------------------------------------------------
//! Get checksum
//------------------------------------------------------------------------
const std::string& GetChecksum() const;

//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
bool ParseServerResponse( const char *data );

//------------------------------------------------------------------------
//! Parse server response and fill up the object
//! Has extended stat information
//------------------------------------------------------------------------
bool ExtendedFormat() const;

//------------------------------------------------------------------------
//! Has checksum
//------------------------------------------------------------------------
bool HasChecksum() const;

private:

static inline std::string TimeToString( uint64_t time )
Expand Down

0 comments on commit e2f697b

Please sign in to comment.