add PBD::toggle_file_existence()
This commit is contained in:
parent
11a702149e
commit
8ff477ab1a
@ -484,4 +484,17 @@ tmp_writable_directory (const char* domain, const string& prefix)
|
||||
return new_test_dir;
|
||||
}
|
||||
|
||||
int
|
||||
toggle_file_existence (string const & path)
|
||||
{
|
||||
if (Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR)) {
|
||||
return g_unlink (path.c_str());
|
||||
}
|
||||
|
||||
int fd = g_open (path.c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666);
|
||||
GError* err;
|
||||
g_close (fd, &err);
|
||||
return !(fd >= 0);
|
||||
}
|
||||
|
||||
} // namespace PBD
|
||||
|
@ -249,6 +249,13 @@ LIBPBD_API void remove_directory (const std::string& dir);
|
||||
*/
|
||||
LIBPBD_API std::string tmp_writable_directory (const char* domain, const std::string& prefix);
|
||||
|
||||
/** If @param path exists, unlink it. If it doesn't exist, create it.
|
||||
*
|
||||
* @return zero if required action was successful, non-zero otherwise.
|
||||
*/
|
||||
|
||||
LIBPBD_API int toggle_file_existence (std::string const &);
|
||||
|
||||
} // namespace PBD
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user