Move file utility function into pbd/file_utils.h and into PBD namespace
authorTim Mayberry <mojofunk@gmail.com>
Sat, 23 Jun 2012 05:08:19 +0000 (05:08 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Sat, 23 Jun 2012 05:08:19 +0000 (05:08 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12865 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/session_state.cc
libs/pbd/file_utils.cc
libs/pbd/filesystem.cc
libs/pbd/pbd/file_utils.h
libs/pbd/pbd/filesystem.h

index d6dfd176ba4ea72142d072220a1ca31dcc3bb81a..302d14fa0d56f6c1f71129f0fa8c3ff4aaea57c3 100644 (file)
@@ -521,7 +521,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
                return -1;
        }
 
-       _writable = sys::exists_and_writable (_path);
+       _writable = exists_and_writable (_path);
 
        if (!session_template.empty()) {
                std::string in_path = session_template_dir_to_file (session_template);
@@ -894,7 +894,7 @@ Session::load_state (string snapshot_name)
 
        set_dirty();
 
-       _writable = sys::exists_and_writable (xmlpath.to_string());
+       _writable = exists_and_writable (xmlpath.to_string());
 
        if (!state_tree->read (xmlpath.to_string())) {
                error << string_compose(_("Could not understand ardour file %1"), xmlpath.to_string()) << endmsg;
index 31db84e88f27a10c083c3314f156fe01fb656c8c..7c3dffe71ffeee1195cc3ec3a9728dd9bfbf46ac 100644 (file)
@@ -207,4 +207,34 @@ path_is_within (std::string const & haystack, std::string needle)
        return false;
 }
 
+bool
+exists_and_writable (const std::string & 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.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;
+               }
+               /* filesystem may be mounted read-only, so even though file
+                * permissions permit access, the mount status does not.
+                * access(2) seems like the best test for this.
+                */
+               if (g_access (p.c_str(), W_OK) != 0) {
+                       return false;
+               }
+       }
+
+       return true;
+}
+
 } // namespace PBD
index 105af6ea32c57cf10ab0875e5562a3f915a9ae18..a154ed8b8eb70dbd454fc884c94312e11e52e096 100644 (file)
@@ -93,37 +93,6 @@ exists (const path & p)
        return Glib::file_test (p.to_string(), Glib::FILE_TEST_EXISTS);
 }
 
-bool
-exists_and_writable (const std::string & 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.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;
-               }
-               /* filesystem may be mounted read-only, so even though file
-                * permissions permit access, the mount status does not.
-                * access(2) seems like the best test for this.
-                */
-               if (g_access (p.to_string().c_str(), W_OK) != 0) {
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-
 bool
 is_directory (const path & p)
 {
index 184e644bba951b25c69840921f251f51dfb62771..72696f6abdf40484d044e4235f15c4f43d960f58 100644 (file)
@@ -127,6 +127,9 @@ bool path_is_within (const std::string &, std::string);
  */
 bool equivalent_paths (const std::string &p1, const std::string &p2);
 
+/// @return true if path at p exists and is writable, false otherwise
+bool exists_and_writable(const std::string & p);
+
 } // namespace PBD
 
 #endif
index ee376df33a2884fff5685d92f1bf477ba73e2607..3df168ea8473650993ae0a8a88a3d89bf4285e6d 100644 (file)
@@ -119,10 +119,6 @@ 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 std::string & p);
-
 /// @return true if path at p is a directory.
 bool is_directory(const path & p);