ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

chroot-fs.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #if defined(POSIX)
00024 
00025 #include "backends/fs/chroot/chroot-fs.h"
00026 
00027 ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFilesystemNode *node) {
00028     _root = Common::normalizePath(root, '/');
00029     _realNode = node;
00030 }
00031 
00032 ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
00033     _root = Common::normalizePath(root, '/');
00034     _realNode = new POSIXFilesystemNode(addPathComponent(root, path));
00035 }
00036 
00037 ChRootFilesystemNode::~ChRootFilesystemNode() {
00038     delete _realNode;
00039 }
00040 
00041 bool ChRootFilesystemNode::exists() const {
00042     return _realNode->exists();
00043 }
00044 
00045 Common::String ChRootFilesystemNode::getDisplayName() const {
00046     return getName();
00047 }
00048 
00049 Common::String ChRootFilesystemNode::getName() const {
00050     return _realNode->AbstractFSNode::getDisplayName();
00051 }
00052 
00053 Common::String ChRootFilesystemNode::getPath() const {
00054     Common::String path = _realNode->getPath();
00055     if (path.size() > _root.size()) {
00056         return Common::String(path.c_str() + _root.size());
00057     }
00058     return Common::String("/");
00059 }
00060 
00061 bool ChRootFilesystemNode::isDirectory() const {
00062     return _realNode->isDirectory();
00063 }
00064 
00065 bool ChRootFilesystemNode::isReadable() const {
00066     return _realNode->isReadable();
00067 }
00068 
00069 bool ChRootFilesystemNode::isWritable() const {
00070     return _realNode->isWritable();
00071 }
00072 
00073 AbstractFSNode *ChRootFilesystemNode::getChild(const Common::String &n) const {
00074     return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getChild(n));
00075 }
00076 
00077 bool ChRootFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
00078     AbstractFSList tmp;
00079     if (!_realNode->getChildren(tmp, mode, hidden)) {
00080         return false;
00081     }
00082 
00083     for (AbstractFSList::iterator i=tmp.begin(); i!=tmp.end(); ++i) {
00084         list.push_back(new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) *i));
00085     }
00086 
00087     return true;
00088 }
00089 
00090 AbstractFSNode *ChRootFilesystemNode::getParent() const {
00091     if (getPath() == "/") return 0;
00092     return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getParent());
00093 }
00094 
00095 Common::SeekableReadStream *ChRootFilesystemNode::createReadStream() {
00096     return _realNode->createReadStream();
00097 }
00098 
00099 Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
00100     return _realNode->createWriteStream();
00101 }
00102 
00103 bool ChRootFilesystemNode::createDirectory() {
00104     return _realNode->createDirectory();
00105 }
00106 
00107 Common::String ChRootFilesystemNode::addPathComponent(const Common::String &path, const Common::String &component) {
00108     const char sep = '/';
00109     if (path.lastChar() == sep && component.firstChar() == sep) {
00110         return Common::String::format("%s%s", path.c_str(), component.c_str() + 1);
00111     }
00112 
00113     if (path.lastChar() == sep || component.firstChar() == sep) {
00114         return Common::String::format("%s%s", path.c_str(), component.c_str());
00115     }
00116 
00117     return Common::String::format("%s%c%s", path.c_str(), sep, component.c_str());
00118 }
00119 
00120 #endif


Generated on Sat May 30 2020 05:00:31 for ResidualVM by doxygen 1.7.1
curved edge   curved edge