mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Path, File, Directory integration
- Replaced all access calls. - Replaced all stat calls. - Obsoleted util.cpp isAbsoluteDirectory calls. - Obsoleted util.cpp expandPath calls.
This commit is contained in:
parent
8e47342a18
commit
b596e96b43
9 changed files with 66 additions and 120 deletions
43
src/util.cpp
43
src/util.cpp
|
@ -341,49 +341,6 @@ const std::string uuid ()
|
|||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// no i18n
|
||||
std::string expandPath (const std::string& in)
|
||||
{
|
||||
std::string copy = in;
|
||||
std::string::size_type tilde;
|
||||
|
||||
if ((tilde = copy.find ("~/")) != std::string::npos)
|
||||
{
|
||||
struct passwd* pw = getpwuid (getuid ());
|
||||
copy.replace (tilde, 1, pw->pw_dir);
|
||||
}
|
||||
else if ((tilde = copy.find ("~")) != std::string::npos)
|
||||
{
|
||||
struct passwd* pw = getpwuid (getuid ());
|
||||
std::string home = pw->pw_dir;
|
||||
home += "/";
|
||||
copy.replace (tilde, 1, home);
|
||||
}
|
||||
else if ((tilde = copy.find ("~")) != std::string::npos)
|
||||
{
|
||||
std::string::size_type slash;
|
||||
if ((slash = copy.find ("/", tilde)) != std::string::npos)
|
||||
{
|
||||
std::string name = copy.substr (tilde + 1, slash - tilde - 1);
|
||||
struct passwd* pw = getpwnam (name.c_str ());
|
||||
if (pw)
|
||||
copy.replace (tilde, slash - tilde, pw->pw_dir);
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool isAbsolutePath (const std::string& in)
|
||||
{
|
||||
if (in.length () && in[0] == '/')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// On Solaris no flock function exists.
|
||||
#ifdef SOLARIS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue