Commit af0dc60f authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

STYLE: reduce indentation in mkDir, minor logic simplication

parent c24fbfd7
......@@ -414,135 +414,122 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
// Directory made OK so return true
return true;
}
else
switch (errno)
{
switch (errno)
case EPERM:
{
case EPERM:
{
FatalErrorInFunction
<< "The filesystem containing " << pathName
<< " does not support the creation of directories."
<< exit(FatalError);
return false;
}
case EEXIST:
{
// Directory already exists so simply return true
return true;
}
case EFAULT:
{
FatalErrorInFunction
<< "" << pathName
<< " points outside your accessible address space."
<< exit(FatalError);
return false;
}
case EACCES:
{
FatalErrorInFunction
<< "The parent directory does not allow write "
"permission to the process,"<< nl
<< "or one of the directories in " << pathName
<< " did not allow search (execute) permission."
<< exit(FatalError);
return false;
}
case ENAMETOOLONG:
{
FatalErrorInFunction
<< "" << pathName << " is too long."
<< exit(FatalError);
return false;
}
FatalErrorInFunction
<< "The filesystem containing " << pathName
<< " does not support the creation of directories."
<< exit(FatalError);
break;
}
case ENOENT:
{
// Part of the path does not exist so try to create it
if (pathName.path().size() && mkDir(pathName.path(), mode))
{
return mkDir(pathName, mode);
}
else
{
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
case EEXIST:
{
// Directory already exists so simply return true
return true;
}
return false;
}
}
case EFAULT:
{
FatalErrorInFunction
<< "" << pathName
<< " points outside your accessible address space."
<< exit(FatalError);
break;
}
case ENOTDIR:
{
FatalErrorInFunction
<< "A component used as a directory in " << pathName
<< " is not, in fact, a directory."
<< exit(FatalError);
case EACCES:
{
FatalErrorInFunction
<< "The parent directory does not allow write "
"permission to the process,"<< nl
<< " or one of the directories in " << pathName
<< " did not allow search (execute) permission."
<< exit(FatalError);
break;
}
return false;
}
case ENAMETOOLONG:
{
FatalErrorInFunction
<< "" << pathName << " is too long."
<< exit(FatalError);
break;
}
case ENOMEM:
case ENOENT:
{
// Part of the path does not exist so try to create it
if (pathName.path().size() && mkDir(pathName.path(), mode))
{
FatalErrorInFunction
<< "Insufficient kernel memory was available to make "
"directory " << pathName << '.'
<< exit(FatalError);
return false;
return mkDir(pathName, mode);
}
case EROFS:
{
FatalErrorInFunction
<< "" << pathName
<< " refers to a file on a read-only filesystem."
<< exit(FatalError);
return false;
}
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
break;
}
case ELOOP:
{
FatalErrorInFunction
<< "Too many symbolic links were encountered in resolving "
<< pathName << '.'
<< exit(FatalError);
case ENOTDIR:
{
FatalErrorInFunction
<< "A component used as a directory in " << pathName
<< " is not, in fact, a directory."
<< exit(FatalError);
break;
}
return false;
}
case ENOMEM:
{
FatalErrorInFunction
<< "Insufficient kernel memory was available to make directory "
<< pathName << '.'
<< exit(FatalError);
break;
}
case ENOSPC:
{
FatalErrorInFunction
<< "The device containing " << pathName
<< " has no room for the new directory or "
<< "the user's disk quota is exhausted."
<< exit(FatalError);
case EROFS:
{
FatalErrorInFunction
<< "" << pathName
<< " refers to a file on a read-only filesystem."
<< exit(FatalError);
break;
}
return false;
}
case ELOOP:
{
FatalErrorInFunction
<< "Too many symbolic links were encountered in resolving "
<< pathName << '.'
<< exit(FatalError);
break;
}
default:
{
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
case ENOSPC:
{
FatalErrorInFunction
<< "The device containing " << pathName
<< " has no room for the new directory or "
<< "the user's disk quota is exhausted."
<< exit(FatalError);
break;
}
return false;
}
default:
{
FatalErrorInFunction
<< "Couldn't create directory " << pathName
<< exit(FatalError);
break;
}
}
return false;
}
......@@ -1100,12 +1087,10 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
{
const fileName dstName(dst/src.name());
return ::rename(src.c_str(), dstName.c_str()) == 0;
}
else
{
return ::rename(src.c_str(), dst.c_str()) == 0;
return (0 == ::rename(src.c_str(), dstName.c_str()));
}
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
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;
}
// Try returning plain file name; if not there, try with .gz
if (::remove(file.c_str()) == 0)
{
return true;
}
else
{
return ::remove(string(file + ".gz").c_str()) == 0;
}
// If removal of plain file name fails, try with .gz
return
(
0 == ::remove(file.c_str())
|| 0 == ::remove((file + ".gz").c_str())
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment