Skip to content

Commit

Permalink
Merge 79f476d into 4256a57
Browse files Browse the repository at this point in the history
  • Loading branch information
arjo129 authored Feb 16, 2022
2 parents 4256a57 + 79f476d commit 110befe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/ignition/common/Filesystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ namespace ignition
/// \return True if _path is a file.
bool IGNITION_COMMON_VISIBLE isFile(const std::string &_path);

/// \brief Check if the given path is relative.
/// \param[in] _path Path.
/// \return True if _path is relative.
bool IGNITION_COMMON_VISIBLE isRelativePath(const std::string &_path);

/// \brief Create a new directory on the filesystem. Intermediate
/// directories must already exist.
/// \param[in] _path The new directory path to create
Expand Down
6 changes: 6 additions & 0 deletions src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ bool ignition::common::isFile(const std::string &_path)
return fs::is_regular_file(_path);
}

/////////////////////////////////////////////////
bool ignition::common::isRelativePath(const std::string &_path)
{
return fs::path(_path).is_relative();
}

/////////////////////////////////////////////////
bool ignition::common::createDirectory(const std::string &_path)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ TEST_F(FilesystemTest, exists)
EXPECT_FALSE(isDirectory(absoluteSubdir));
}

/////////////////////////////////////////////////
TEST_F(FilesystemTest, relative)
{
#ifndef _WIN32
std::string absPath {"/tmp/fstest"};
std::string relPath {"../fstest"};
#else
std::string absPath {"C:\\Users\\user\\Desktop\\test.txt"};
std::string relPath {"user\\Desktop\\test.txt"};
#endif
EXPECT_FALSE(isRelativePath(absPath));
EXPECT_TRUE(isRelativePath(relPath));
}

// The symlink tests require special permissions to work on Windows,
// so they will be disabled by default. For more information, see:
// https://github.com/ignitionrobotics/ign-common/issues/21
Expand Down

0 comments on commit 110befe

Please sign in to comment.