2015-12-01 18:53:52 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(POSIX)
|
|
|
|
|
|
|
|
// Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
|
|
|
|
// Also with clock() in sys/time.h in some Mac OS X SDKs.
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit //Needed for IRIX's unistd.h
|
|
|
|
|
|
|
|
#include "backends/fs/chroot/chroot-fs.h"
|
|
|
|
|
|
|
|
ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFilesystemNode *node) {
|
2015-12-03 07:13:15 +01:00
|
|
|
_root = Common::normalizePath(root, '/');
|
|
|
|
_realNode = node;
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
|
2015-12-03 07:13:15 +01:00
|
|
|
_root = Common::normalizePath(root, '/');
|
2016-01-06 15:43:42 +01:00
|
|
|
_realNode = new POSIXFilesystemNode(addPathComponent(root, path));
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ChRootFilesystemNode::~ChRootFilesystemNode() {
|
2015-12-03 07:13:15 +01:00
|
|
|
delete _realNode;
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChRootFilesystemNode::exists() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->exists();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::String ChRootFilesystemNode::getDisplayName() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return getName();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::String ChRootFilesystemNode::getName() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->AbstractFSNode::getDisplayName();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::String ChRootFilesystemNode::getPath() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
Common::String path = _realNode->getPath();
|
|
|
|
if (path.size() > _root.size()) {
|
|
|
|
return Common::String(path.c_str() + _root.size());
|
|
|
|
}
|
|
|
|
return Common::String("/");
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChRootFilesystemNode::isDirectory() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->isDirectory();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChRootFilesystemNode::isReadable() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->isReadable();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChRootFilesystemNode::isWritable() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->isWritable();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractFSNode *ChRootFilesystemNode::getChild(const Common::String &n) const {
|
2016-01-06 10:36:25 +01:00
|
|
|
return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getChild(n));
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChRootFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
|
2015-12-03 07:13:15 +01:00
|
|
|
AbstractFSList tmp;
|
|
|
|
if (!_realNode->getChildren(tmp, mode, hidden)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-01 18:53:52 +01:00
|
|
|
|
2015-12-03 07:13:15 +01:00
|
|
|
for (AbstractFSList::iterator i=tmp.begin(); i!=tmp.end(); ++i) {
|
|
|
|
list.push_back(new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) *i));
|
|
|
|
}
|
2015-12-01 18:53:52 +01:00
|
|
|
|
2015-12-03 07:13:15 +01:00
|
|
|
return true;
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractFSNode *ChRootFilesystemNode::getParent() const {
|
2015-12-03 07:13:15 +01:00
|
|
|
if (getPath() == "/") return 0;
|
2016-01-06 10:36:25 +01:00
|
|
|
return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getParent());
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::SeekableReadStream *ChRootFilesystemNode::createReadStream() {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->createReadStream();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
|
2015-12-03 07:13:15 +01:00
|
|
|
return _realNode->createWriteStream();
|
2015-12-01 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 15:43:42 +01:00
|
|
|
Common::String ChRootFilesystemNode::addPathComponent(const Common::String &path, const Common::String &component) {
|
|
|
|
const char sep = '/';
|
|
|
|
if (path.lastChar() == sep && component.firstChar() == sep) {
|
|
|
|
return Common::String::format("%s%s", path.c_str(), component.c_str() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.lastChar() == sep || component.firstChar() == sep) {
|
|
|
|
return Common::String::format("%s%s", path.c_str(), component.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Common::String::format("%s%c%s", path.c_str(), sep, component.c_str());
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:53:52 +01:00
|
|
|
#endif
|