13
0

add PBD::sys::path::exists_and_writable() method to help replace access(2)

git-svn-id: svn://localhost/ardour2/branches/3.0@9338 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-04-09 15:27:22 +00:00
parent aca716c0d6
commit 93a24066de
2 changed files with 28 additions and 0 deletions

View File

@ -90,6 +90,30 @@ exists (const path & p)
return Glib::file_test (p.to_string(), Glib::FILE_TEST_EXISTS);
}
bool
exists_and_writable (const path & p)
{
/* writable() really reflects the whole folder, but if for any
reason the session state file can't be written to, still
make us unwritable.
*/
struct stat statbuf;
if (g_stat (p.to_string().c_str(), &statbuf) != 0) {
/* doesn't exist - not writable */
return false;
} else {
if (!(statbuf.st_mode & S_IWUSR)) {
/* exists and is not writable */
return false;
}
}
return true;
}
bool
is_directory (const path & p)
{

View File

@ -119,6 +119,10 @@ inline path operator/ (const path& lhs, const path& rhs)
/// @return true if path at p exists
bool exists(const path & p);
/// @return true if path at p exists and is writable, false otherwise
bool exists_and_writable(const path & p);
/// @return true if path at p is a directory.
bool is_directory(const path & p);