Storage Engine API
paths.h
Go to the documentation of this file.
1 // @file paths.h
2 // file paths and directory handling
3 
4 /* Copyright 2010 10gen Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License, version 3,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * As a special exception, the copyright holders give permission to link the
19  * code of portions of this program with the OpenSSL library under certain
20  * conditions as described in each individual source file and distribute
21  * linked combinations including the program with the OpenSSL library. You
22  * must comply with the GNU Affero General Public License in all respects
23  * for all of the code used other than as permitted herein. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you do not
26  * wish to do so, delete this exception statement from your version. If you
27  * delete this exception statement from all source files in the program,
28  * then also delete it in the license file.
29  */
30 
31 #pragma once
32 
33 #include <boost/filesystem/path.hpp>
34 #include <fcntl.h>
35 #include <sys/stat.h>
36 #include <sys/types.h>
37 
38 #include "mongo/util/mongoutils/str.h"
39 
41 
42 namespace mongo {
43 
44 using namespace mongoutils;
45 
49 struct RelativePath {
50  std::string _p;
51 
52  bool empty() const {
53  return _p.empty();
54  }
55 
56  static RelativePath fromRelativePath(const std::string& f) {
57  RelativePath rp;
58  rp._p = f;
59  return rp;
60  }
61 
65  static RelativePath fromFullPath(boost::filesystem::path dbpath, boost::filesystem::path f);
66 
67  std::string toString() const {
68  return _p;
69  }
70 
71  bool operator!=(const RelativePath& r) const {
72  return _p != r._p;
73  }
74  bool operator==(const RelativePath& r) const {
75  return _p == r._p;
76  }
77  bool operator<(const RelativePath& r) const {
78  return _p < r._p;
79  }
80 
81  std::string asFullPath() const {
82  boost::filesystem::path x(storageGlobalParams.dbpath);
83  x /= _p;
84  return x.string();
85  }
86 };
87 
88 dev_t getPartition(const std::string& path);
89 
90 inline bool onSamePartition(const std::string& path1, const std::string& path2) {
91  dev_t dev1 = getPartition(path1);
92  dev_t dev2 = getPartition(path2);
93 
94  return dev1 == dev2;
95 }
96 
97 void flushMyDirectory(const boost::filesystem::path& file);
98 
99 boost::filesystem::path ensureParentDirCreated(const boost::filesystem::path& p);
100 }
static RelativePath fromRelativePath(const std::string &f)
Definition: paths.h:56
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
std::string _p
Definition: paths.h:50
boost::filesystem::path ensureParentDirCreated(const boost::filesystem::path &p)
Aliases for Win32 CRT functions.
Definition: file_allocator.cpp:115
bool operator<(const RelativePath &r) const
Definition: paths.h:77
bool onSamePartition(const std::string &path1, const std::string &path2)
Definition: paths.h:90
void flushMyDirectory(const boost::filesystem::path &file)
Definition: paths.cpp:69
std::string dbpath
Definition: storage_options.h:62
bool operator==(const RelativePath &r) const
Definition: paths.h:74
bool empty() const
Definition: paths.h:52
std::string toString() const
Definition: paths.h:67
dev_t getPartition(const std::string &path)
Definition: paths.cpp:57
bool operator!=(const RelativePath &r) const
Definition: paths.h:71
StorageGlobalParams storageGlobalParams
Definition: storage_options.cpp:39
std::string asFullPath() const
Definition: paths.h:81
this is very much like a boost::path.
Definition: paths.h:49