Remove unused method PBD::sys::path::leaf
[ardour.git] / libs / pbd / filesystem.cc
1 /*
2         Copyright (C) 2007 Tim Mayberry 
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <sys/stat.h>
20
21 #include <glib.h>
22 #include <glib/gstdio.h>
23
24 #include <giomm/file.h>
25
26 #include <cerrno>
27 #include <fstream>
28
29 #include <glibmm/fileutils.h>
30 #include <glibmm/miscutils.h>
31
32 #include "pbd/filesystem.h"
33 #include "pbd/error.h"
34 #include "pbd/compose.h"
35 #include "pbd/pathscanner.h"
36
37 #include "i18n.h"
38
39 using namespace std;
40
41 namespace PBD {
42
43 namespace sys {
44         
45 path&
46 path::operator/=(const path& rhs)
47 {
48         m_path = Glib::build_filename(m_path, rhs.m_path);
49         return *this;
50 }
51
52 path&
53 path::operator/=(const string& rhs)
54 {
55         m_path = Glib::build_filename(m_path, rhs);
56         return *this;
57 }
58
59 path&
60 path::operator/=(const char* rhs)
61 {
62         m_path = Glib::build_filename(m_path, rhs);
63         return *this;
64 }
65
66 bool
67 exists (const path & p)
68 {
69         return Glib::file_test (p.to_string(), Glib::FILE_TEST_EXISTS);
70 }
71
72 bool
73 is_directory (const path & p)
74 {
75         return Glib::file_test (p.to_string(), Glib::FILE_TEST_IS_DIR);
76 }
77
78 bool
79 create_directory(const path & p)
80 {
81         if(is_directory(p)) return false;
82
83         int error = g_mkdir (p.to_string().c_str(), S_IRWXU|S_IRWXG|S_IRWXO);
84
85         if(error == -1)
86         {
87                 throw filesystem_error(g_strerror(errno), errno);
88         }
89         return true;
90 }
91
92 bool
93 create_directories(const path & p)
94 {
95         if(is_directory(p)) return false;
96
97         int error = g_mkdir_with_parents (p.to_string().c_str(), S_IRWXU|S_IRWXG|S_IRWXO);
98
99         if(error == -1)
100         {
101                 throw filesystem_error(g_strerror(errno), errno);
102         }
103         return true;
104 }
105         
106 } // namespace sys
107
108 } // namespace PBD