Minor fixes to FSNodePOSIX.

This commit is contained in:
Stephen Anthony 2022-11-12 21:44:50 -03:30
parent 25c882b4bd
commit 788c836130
2 changed files with 19 additions and 18 deletions

View File

@ -89,7 +89,7 @@ string FSNodePOSIX::getShortPath() const
if (home != EmptyString && BSPF::startsWithIgnoreCase(_path, home))
{
string path = "~";
const char* offset = _path.c_str() + home.size();
const char* const offset = _path.c_str() + home.size();
if (*offset != FSNode::PATH_SEPARATOR)
path += FSNode::PATH_SEPARATOR;
path += offset;
@ -121,8 +121,8 @@ AbstractFSNodePtr FSNodePOSIX::getParent() const
if (_path == ROOT_DIR)
return nullptr;
const char* start = _path.c_str();
const char* end = lastPathComponent(_path);
const char* const start = _path.c_str();
const char* const end = lastPathComponent(_path);
return make_unique<FSNodePOSIX>(string(start, static_cast<size_t>(end - start)));
}
@ -146,7 +146,8 @@ bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
continue;
string newPath(_path);
if (newPath.length() > 0 && newPath[newPath.length()-1] != FSNode::PATH_SEPARATOR)
if (newPath.length() > 0 &&
newPath[newPath.length()-1] != FSNode::PATH_SEPARATOR)
newPath += FSNode::PATH_SEPARATOR;
newPath += dp->d_name;
@ -162,7 +163,7 @@ bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
{
entry._isDirectory = (dp->d_type == DT_DIR);
entry._isFile = (dp->d_type == DT_REG);
// entry._size will be calculated next time ::getSize() is called
// entry._size will be calculated first time ::getSize() is called
if (entry._isDirectory)
entry._path += FSNode::PATH_SEPARATOR;
@ -178,7 +179,7 @@ bool FSNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) const
(mode == FSNode::ListMode::DirectoriesOnly && !entry._isDirectory))
continue;
myList.emplace_back(make_shared<FSNodePOSIX>(entry));
myList.emplace_back(make_unique<FSNodePOSIX>(entry));
}
closedir(dirp);
@ -220,4 +221,4 @@ bool FSNodePOSIX::rename(const string& newfile)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* FSNodePOSIX::ourHomeDir = std::getenv("HOME"); // NOLINT (not thread safe)
const char* const FSNodePOSIX::ourHomeDir = std::getenv("HOME"); // NOLINT (not thread safe)

View File

@ -90,7 +90,7 @@ class FSNodePOSIX : public AbstractFSNode
bool _isFile{false}, _isDirectory{true};
mutable size_t _size{0};
static const char* ourHomeDir;
static const char* const ourHomeDir;
};
#endif