diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2014-11-29 13:44:11 +0700 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2014-12-03 17:31:04 +0700 |
commit | 1abe8f4e42542cad9b455f0b009707d8da47f496 (patch) | |
tree | 19d332abf6a528d56f08e7eb35c46cf28a0710c6 /libs/pbd/file_utils.cc | |
parent | 2b03521ef9fca5f14bafef29c87225e7f1687047 (diff) |
Add PBD::tmp_writable_directory utility function to pbd/file_utils.h/cc
Diffstat (limited to 'libs/pbd/file_utils.cc')
-rw-r--r-- | libs/pbd/file_utils.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 099d1be2d6..849d7f05fd 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -468,4 +468,21 @@ remove_directory (const std::string& dir) remove_directory_internal (dir, 0, 0, false); } +string +tmp_writable_directory (const char* domain, const string& prefix) +{ + std::string tmp_dir = Glib::build_filename (g_get_tmp_dir(), domain); + std::string dir_name; + std::string new_test_dir; + do { + ostringstream oss; + oss << prefix; + oss << g_random_int (); + dir_name = oss.str(); + new_test_dir = Glib::build_filename (tmp_dir, dir_name); + if (Glib::file_test (new_test_dir, Glib::FILE_TEST_EXISTS)) continue; + } while (g_mkdir_with_parents (new_test_dir.c_str(), 0755) != 0); + return new_test_dir; +} + } // namespace PBD |