mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-25 12:17:20 +02:00
Enhancement
- Directory handling enhancements with Directory::cwd and Directory::up methods, with unit tests.
This commit is contained in:
parent
a9058612a7
commit
ddd7bc3f0a
3 changed files with 49 additions and 1 deletions
|
@ -142,6 +142,35 @@ std::vector <std::string> Directory::listRecursive ()
|
|||
return files;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Directory::cwd ()
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
getcwd (buf, PATH_MAX - 1);
|
||||
return std::string (buf);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Directory::up ()
|
||||
{
|
||||
if (_data == "/")
|
||||
return false;
|
||||
|
||||
std::string::size_type slash = _data.rfind ('/');
|
||||
if (slash == 0)
|
||||
{
|
||||
_data = "/"; // Root dir should retain the slash.
|
||||
return true;
|
||||
}
|
||||
else if (slash != std::string::npos)
|
||||
{
|
||||
_data = _data.substr (0, slash);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Directory::list (
|
||||
const std::string& base,
|
||||
|
|
|
@ -49,6 +49,9 @@ public:
|
|||
std::vector <std::string> list ();
|
||||
std::vector <std::string> listRecursive ();
|
||||
|
||||
static std::string cwd ();
|
||||
bool up ();
|
||||
|
||||
private:
|
||||
void list (const std::string&, std::vector <std::string>&, bool);
|
||||
bool remove_directory (const std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue