Skip to content

Commit

Permalink
Changed name increment
Browse files Browse the repository at this point in the history
- Fixed style issues
  • Loading branch information
jackdelv committed Dec 17, 2024
1 parent d584c6b commit 8c3bc48
Showing 1 changed file with 60 additions and 29 deletions.
89 changes: 60 additions & 29 deletions dali/dfuXRefLib/dfuxreflib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ struct CLogicalNameEntry: public CInterface
RemoteFilename &constructPartFilename(unsigned partNo, bool replicate, RemoteFilename &rfn)
{
if (!plane)
throw MakeStringException(0, "Plane definition \"%s\" is missing for File", grpname.str());
throw makeStringExceptionV(0, "Plane definition \"%s\" is missing for File", grpname.str());
unsigned numDevices = plane->numDevices();
bool r = replicate?1:0;

Expand Down Expand Up @@ -964,13 +964,12 @@ static void parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
if (startsWith(name, prefix) && name[prefixLen] == PATHSEPCHAR)
{
mname.ensureCapacity(strlen(name));
mname.append(prefix);
name += prefixLen;
mname.append(prefix).append(PATHSEPCHAR);
name += prefixLen + 1;
stripeNum = 0;
if (plane.getPropInt("@numDevices") > 1)
{
name++;
if (!*name || *name!='d')
if (*name!='d')
throw makeStringExceptionV(-1, "In storage plane definition numDevices>1, but no stripe sub-directory found in file %s", filename);
name++;
if (*name==PATHSEPCHAR)
Expand All @@ -980,8 +979,9 @@ static void parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
stripeNum = stripeNum*10+(*name-'0');
name++;
}
if (!*name || *name!=PATHSEPCHAR)
if (*name!=PATHSEPCHAR)
throw makeStringExceptionV(-1, "In storage plane definition numDevices>1, but no stripe sub-directory found in file %s", filename);
name++;
if (stripeNum>=plane.getPropInt("@numDevices"))
throw makeStringExceptionV(-1, "Stripe number in file %s is greater than numDevices in storage plane definition", filename);
}
Expand All @@ -996,14 +996,17 @@ static void parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
max = 0;
dirPerPart = 0;
const char * cur = name;
for (;;) {
for (;;)
{
char c=*cur;
if (!c)
break;
if ((c=='.')&&(cur[1]=='_')) {
if ((c=='.')&&(cur[1]=='_'))
{
unsigned pn = 0;
const char *s = cur+2;
while (*s&&isdigit(*s)) {
while (*s&&isdigit(*s))
{
pn = pn*10+(*s-'0');
s++;
}
Expand All @@ -1016,7 +1019,7 @@ static void parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
for (int i=1;d!=name&&isdigit(*d);i*=10,d--)
dirPerPart += (*d-'0')*i;
// If a dir-per-part number was found, check that it matches the part number
if (*d&&*d=='/')
if (*d=='/')
{
if (dirPerPart!=pn)
throw makeStringExceptionV(-1, "Dir-per-part # does not match part # of file %s", filename);
Expand All @@ -1025,14 +1028,18 @@ static void parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
else
mname.append(cur-name,name);

if (pn&&(memicmp(s,"_of_",4)==0)) {
if (pn&&(memicmp(s,"_of_",4)==0))
{
unsigned mn = 0;
s += 4;
while (*s&&isdigit(*s)) {
while (*s&&isdigit(*s))
{
mn = mn*10+(*s-'0');
s++;
}
if ((mn!=0)&&((*s==0)||(*s=='.'))&&(mn>=pn)) { // NB allow trailing extension
if ((mn!=0)&&((*s==0)||(*s=='.'))&&(mn>=pn))
{
// NB allow trailing extension
mname.append("._$P$_of_").append(mn);
if (*s)
mname.append(s);
Expand Down Expand Up @@ -3091,87 +3098,111 @@ class DFUXrefLibTests : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL_MESSAGE("Replicate is incorrect",true,replicate);

// A file without a storage plane throws an exception
try {
try
{
parseFileName("/test/myname._1_of_3", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("Could not find matching prefix in plane definition for file /test/myname._1_of_3",msg.str());
}

// A file with a storage plane that has numDevices>1 but no stripe number in the path throws an exception
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/test/myname.42_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("In storage plane definition numDevices>1, but no stripe sub-directory found in file /var/lib/HPCCSystems/hpcc-data-two/test/myname.42_of_100",msg.str());
}

// A file with a storage plane that has numDevices>1 but no stripe number in the path throws an exception
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/d/test/myname.42_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("In storage plane definition numDevices>1, but no stripe sub-directory found in file /var/lib/HPCCSystems/hpcc-data-two/d/test/myname.42_of_100",msg.str());
}

// A file with a storage plane that has numDevices>1 but no stripe number in the path throws an exception
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/datadir/test/myname.42_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("In storage plane definition numDevices>1, but no stripe sub-directory found in file /var/lib/HPCCSystems/hpcc-data-two/datadir/test/myname.42_of_100",msg.str());
}

// A file where the stripe number is equal to numDevices(111) throws an exception
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/d111/test/myname.42_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("Stripe number in file /var/lib/HPCCSystems/hpcc-data-two/d111/test/myname.42_of_100 is greater than numDevices in storage plane definition",msg.str());
}

// A file where the dir-per-part number does not match the part number
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/d1/test/42/myname._43_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("Dir-per-part # does not match part # of file /var/lib/HPCCSystems/hpcc-data-two/d1/test/42/myname._43_of_100",msg.str());
}

// A file where the part number is greater than the max part number
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/d1/test/1000/myname._1000_of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
CPPUNIT_ASSERT_EQUAL_STR("Incorrect max part number(100) and part number (1000) in file /var/lib/HPCCSystems/hpcc-data-two/d1/test/1000/myname._1000_of_100",msg.str());
}

// A file where the part number is missing
try {
try
{
parseFileName("/var/lib/HPCCSystems/hpcc-data-two/d1/test/myname._of_100", mname.clear(), num, max, stripeNum, dirPerPart, replicate);
CPPUNIT_ASSERT(false);
} catch (IException *e) {
}
catch (IException *e)
{
StringBuffer msg;
e->errorMessage(msg);
e->Release();
Expand Down

0 comments on commit 8c3bc48

Please sign in to comment.