summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-04-09 15:27:22 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-04-09 15:27:22 +0000
commit93a24066dee65230769be7f6ac55ecf87d490acf (patch)
treeffcd7b99fe2d044481a6b6b6e51d8f38a930c9d3 /libs/pbd
parentaca716c0d6720cce6c102a02f60e1c32cd38fdfd (diff)
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
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/filesystem.cc24
-rw-r--r--libs/pbd/pbd/filesystem.h4
2 files changed, 28 insertions, 0 deletions
diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc
index 9c05962a6b..886cd24d99 100644
--- a/libs/pbd/filesystem.cc
+++ b/libs/pbd/filesystem.cc
@@ -91,6 +91,30 @@ exists (const path & p)
}
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)
{
return Glib::file_test (p.to_string(), Glib::FILE_TEST_IS_DIR);
diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h
index f7cf1882fd..7de9bda00f 100644
--- a/libs/pbd/pbd/filesystem.h
+++ b/libs/pbd/pbd/filesystem.h
@@ -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);