STYLE: reduce indentation in mkDir, minor logic simplication

This commit is contained in:
Mark Olesen
2019-04-02 16:56:00 +02:00
committed by Andrew Heather
parent c24fbfd7e3
commit af0dc60fa1

View File

@ -414,8 +414,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
// Directory made OK so return true // Directory made OK so return true
return true; return true;
} }
else
{
switch (errno) switch (errno)
{ {
case EPERM: case EPERM:
@ -424,8 +423,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "The filesystem containing " << pathName << "The filesystem containing " << pathName
<< " does not support the creation of directories." << " does not support the creation of directories."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case EEXIST: case EEXIST:
@ -440,8 +438,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "" << pathName << "" << pathName
<< " points outside your accessible address space." << " points outside your accessible address space."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case EACCES: case EACCES:
@ -449,11 +446,10 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
FatalErrorInFunction FatalErrorInFunction
<< "The parent directory does not allow write " << "The parent directory does not allow write "
"permission to the process,"<< nl "permission to the process,"<< nl
<< "or one of the directories in " << pathName << " or one of the directories in " << pathName
<< " did not allow search (execute) permission." << " did not allow search (execute) permission."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case ENAMETOOLONG: case ENAMETOOLONG:
@ -461,8 +457,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
FatalErrorInFunction FatalErrorInFunction
<< "" << pathName << " is too long." << "" << pathName << " is too long."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case ENOENT: case ENOENT:
@ -472,14 +467,11 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
{ {
return mkDir(pathName, mode); return mkDir(pathName, mode);
} }
else
{
FatalErrorInFunction FatalErrorInFunction
<< "Couldn't create directory " << pathName << "Couldn't create directory " << pathName
<< exit(FatalError); << exit(FatalError);
break;
return false;
}
} }
case ENOTDIR: case ENOTDIR:
@ -488,18 +480,16 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "A component used as a directory in " << pathName << "A component used as a directory in " << pathName
<< " is not, in fact, a directory." << " is not, in fact, a directory."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case ENOMEM: case ENOMEM:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Insufficient kernel memory was available to make " << "Insufficient kernel memory was available to make directory "
"directory " << pathName << '.' << pathName << '.'
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case EROFS: case EROFS:
@ -508,8 +498,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "" << pathName << "" << pathName
<< " refers to a file on a read-only filesystem." << " refers to a file on a read-only filesystem."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case ELOOP: case ELOOP:
@ -518,8 +507,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< "Too many symbolic links were encountered in resolving " << "Too many symbolic links were encountered in resolving "
<< pathName << '.' << pathName << '.'
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
case ENOSPC: case ENOSPC:
@ -529,8 +517,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
<< " has no room for the new directory or " << " has no room for the new directory or "
<< "the user's disk quota is exhausted." << "the user's disk quota is exhausted."
<< exit(FatalError); << exit(FatalError);
break;
return false;
} }
default: default:
@ -538,11 +525,11 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
FatalErrorInFunction FatalErrorInFunction
<< "Couldn't create directory " << pathName << "Couldn't create directory " << pathName
<< exit(FatalError); << exit(FatalError);
break;
}
}
return false; return false;
}
}
}
} }
@ -1100,12 +1087,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
{ {
const fileName dstName(dst/src.name()); const fileName dstName(dst/src.name());
return ::rename(src.c_str(), dstName.c_str()) == 0; return (0 == ::rename(src.c_str(), dstName.c_str()));
}
else
{
return ::rename(src.c_str(), dst.c_str()) == 0;
} }
return (0 == ::rename(src.c_str(), dst.c_str()));
} }
@ -1146,7 +1131,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
// possible index where we have no choice // possible index where we have no choice
if (!exists(dstName, false) || n == maxIndex) if (!exists(dstName, false) || n == maxIndex)
{ {
return ::rename(src.c_str(), dstName.c_str()) == 0; return (0 == ::rename(src.c_str(), dstName.c_str()));
} }
} }
} }
@ -1174,15 +1159,13 @@ bool Foam::rm(const fileName& file)
return false; return false;
} }
// Try returning plain file name; if not there, try with .gz // If removal of plain file name fails, try with .gz
if (::remove(file.c_str()) == 0)
{ return
return true; (
} 0 == ::remove(file.c_str())
else || 0 == ::remove((file + ".gz").c_str())
{ );
return ::remove(string(file + ".gz").c_str()) == 0;
}
} }