[generator:tests] Add directory recursive cleaner helper
This commit is contained in:
parent
4d68905469
commit
64db2c5392
3 changed files with 27 additions and 15 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include "platform/platform_tests_support/scoped_dir.hpp"
|
||||
#include "platform/platform_tests_support/scoped_file.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
@ -13,6 +14,7 @@
|
|||
namespace generator_tests
|
||||
{
|
||||
using Tags = std::vector<std::pair<std::string, std::string>>;
|
||||
using platform::tests_support::ScopedDir;
|
||||
using platform::tests_support::ScopedFile;
|
||||
|
||||
OsmElement MakeOsmElement(uint64_t id, Tags const & tags, OsmElement::EntityType t);
|
||||
|
|
|
@ -11,10 +11,11 @@ namespace platform
|
|||
{
|
||||
namespace tests_support
|
||||
{
|
||||
ScopedDir::ScopedDir(std::string const & relativePath)
|
||||
ScopedDir::ScopedDir(std::string const & relativePath, bool recursiveForceRemove)
|
||||
: m_fullPath(base::JoinPath(GetPlatform().WritableDir(), relativePath))
|
||||
, m_relativePath(relativePath)
|
||||
, m_reset(false)
|
||||
, m_recursiveForceRemove{recursiveForceRemove}
|
||||
{
|
||||
Platform::EError ret = Platform::MkDir(GetFullPath());
|
||||
switch (ret)
|
||||
|
@ -43,20 +44,28 @@ ScopedDir::~ScopedDir()
|
|||
return;
|
||||
|
||||
std::string const fullPath = GetFullPath();
|
||||
Platform::EError ret = Platform::RmDir(fullPath);
|
||||
switch (ret)
|
||||
if (m_recursiveForceRemove)
|
||||
{
|
||||
case Platform::ERR_OK:
|
||||
break;
|
||||
case Platform::ERR_FILE_DOES_NOT_EXIST:
|
||||
LOG(LERROR, (fullPath, "was deleted before destruction of ScopedDir."));
|
||||
break;
|
||||
case Platform::ERR_DIRECTORY_NOT_EMPTY:
|
||||
LOG(LERROR, ("There are files in", fullPath));
|
||||
break;
|
||||
default:
|
||||
LOG(LERROR, ("Platform::RmDir() error for", fullPath, ":", ret));
|
||||
break;
|
||||
if (!Platform::RmDirRecursively(fullPath))
|
||||
LOG(LERROR, ("Fail to force remove directory", fullPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
Platform::EError const ret = Platform::RmDir(fullPath);
|
||||
switch (ret)
|
||||
{
|
||||
case Platform::ERR_OK:
|
||||
break;
|
||||
case Platform::ERR_FILE_DOES_NOT_EXIST:
|
||||
LOG(LERROR, (fullPath, "was deleted before destruction of ScopedDir."));
|
||||
break;
|
||||
case Platform::ERR_DIRECTORY_NOT_EMPTY:
|
||||
LOG(LERROR, ("There are files in", fullPath));
|
||||
break;
|
||||
default:
|
||||
LOG(LERROR, ("Platform::RmDir() error for", fullPath, ":", ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class ScopedDir
|
|||
public:
|
||||
/// Creates test dir in a writable directory.
|
||||
/// @param path Path for a testing directory, should be relative to writable-dir.
|
||||
ScopedDir(std::string const & relativePath);
|
||||
ScopedDir(std::string const & relativePath, bool recursiveForceRemove = false);
|
||||
|
||||
ScopedDir(ScopedDir const & parent, std::string const & name);
|
||||
|
||||
|
@ -34,6 +34,7 @@ private:
|
|||
std::string const m_fullPath;
|
||||
std::string const m_relativePath;
|
||||
bool m_reset;
|
||||
bool m_recursiveForceRemove;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(ScopedDir);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue