2007-05-30 21:56:52 +00: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.
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 02:34:23 +01:00
|
|
|
*
|
2002-11-13 17:16:18 +00:00
|
|
|
*/
|
|
|
|
|
2017-03-01 14:00:17 -06:00
|
|
|
#if defined(POSIX) || defined(PLAYSTATION3) || defined(PSP2)
|
2003-11-03 22:20:51 +00:00
|
|
|
|
2011-05-03 14:30:25 +02:00
|
|
|
// Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
|
2011-05-03 18:25:30 +02:00
|
|
|
// Also with clock() in sys/time.h in some Mac OS X SDKs.
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
2011-05-03 14:30:25 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
|
2011-05-03 10:33:03 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
|
2011-05-23 19:11:19 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
2011-06-04 16:55:58 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit //Needed for IRIX's unistd.h
|
2018-08-16 20:08:54 +01:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_random
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_srandom
|
2011-05-03 10:33:03 +02:00
|
|
|
|
2008-08-22 11:19:41 +00:00
|
|
|
#include "backends/fs/posix/posix-fs.h"
|
2008-09-03 12:56:46 +00:00
|
|
|
#include "backends/fs/stdiostream.h"
|
2008-09-02 15:19:31 +00:00
|
|
|
#include "common/algorithm.h"
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2003-03-25 12:14:14 +00:00
|
|
|
#include <sys/param.h>
|
2002-11-15 17:05:50 +00:00
|
|
|
#include <sys/stat.h>
|
2019-04-15 16:09:06 +01:00
|
|
|
#ifdef MACOSX
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2017-03-01 14:00:17 -06:00
|
|
|
#ifdef PSP2
|
|
|
|
#include "backends/fs/psp2/psp2-dirent.h"
|
|
|
|
#define mkdir sceIoMkdir
|
|
|
|
#else
|
2002-11-13 17:16:18 +00:00
|
|
|
#include <dirent.h>
|
2017-03-01 14:00:17 -06:00
|
|
|
#endif
|
2002-11-15 17:54:38 +00:00
|
|
|
#include <stdio.h>
|
2016-01-29 20:09:29 +01:00
|
|
|
#include <errno.h>
|
2016-05-27 16:29:42 +02:00
|
|
|
#include <fcntl.h>
|
2019-04-15 16:09:06 +01:00
|
|
|
#include <unistd.h>
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2008-08-27 18:38:06 +00:00
|
|
|
#ifdef __OS2__
|
|
|
|
#define INCL_DOS
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-04-15 16:09:06 +01:00
|
|
|
bool POSIXFilesystemNode::exists() const {
|
|
|
|
return access(_path.c_str(), F_OK) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool POSIXFilesystemNode::isReadable() const {
|
|
|
|
return access(_path.c_str(), R_OK) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool POSIXFilesystemNode::isWritable() const {
|
|
|
|
return access(_path.c_str(), W_OK) == 0;
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
void POSIXFilesystemNode::setFlags() {
|
|
|
|
struct stat st;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
_isValid = (0 == stat(_path.c_str(), &st));
|
2007-06-04 03:46:56 +00:00
|
|
|
_isDirectory = _isValid ? S_ISDIR(st.st_mode) : false;
|
2004-02-01 01:31:50 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
POSIXFilesystemNode::POSIXFilesystemNode(const Common::String &p) {
|
2006-04-03 21:18:24 +00:00
|
|
|
assert(p.size() > 0);
|
2004-02-01 01:31:50 +00:00
|
|
|
|
2018-03-28 22:58:39 -05:00
|
|
|
#ifdef PSP2
|
|
|
|
if (p == "/") {
|
|
|
|
_isDirectory = true;
|
|
|
|
_isValid = false;
|
|
|
|
_path = p;
|
|
|
|
_displayName = p;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-09 17:28:29 +00:00
|
|
|
// Expand "~/" to the value of the HOME env variable
|
|
|
|
if (p.hasPrefix("~/")) {
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
if (home != NULL && strlen(home) < MAXPATHLEN) {
|
|
|
|
_path = home;
|
|
|
|
// Skip over the tilda. We know that p contains at least
|
|
|
|
// two chars, so this is safe:
|
|
|
|
_path += p.c_str() + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_path = p;
|
|
|
|
}
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-17 18:26:44 +00:00
|
|
|
#ifdef __OS2__
|
|
|
|
// On OS/2, 'X:/' is a root of drive X, so we should not remove that last
|
|
|
|
// slash.
|
|
|
|
if (!(_path.size() == 3 && _path.hasSuffix(":/")))
|
|
|
|
#endif
|
2008-09-02 15:19:31 +00:00
|
|
|
// Normalize the path (that is, remove unneeded slashes etc.)
|
|
|
|
_path = Common::normalizePath(_path, '/');
|
|
|
|
_displayName = Common::lastPathComponent(_path, '/');
|
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
// TODO: should we turn relative paths into absolute ones?
|
2008-09-02 15:19:31 +00:00
|
|
|
// Pro: Ensures the "getParent" works correctly even for relative dirs.
|
|
|
|
// Contra: The user may wish to use (and keep!) relative paths in his
|
|
|
|
// config file, and converting relative to absolute paths may hurt him...
|
|
|
|
//
|
|
|
|
// An alternative approach would be to change getParent() to work correctly
|
|
|
|
// if "_path" is the empty string.
|
|
|
|
#if 0
|
|
|
|
if (!_path.hasPrefix("/")) {
|
|
|
|
char buf[MAXPATHLEN+1];
|
|
|
|
getcwd(buf, MAXPATHLEN);
|
|
|
|
strcat(buf, "/");
|
|
|
|
_path = buf + _path;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// TODO: Should we enforce that the path is absolute at this point?
|
|
|
|
//assert(_path.hasPrefix("/"));
|
2006-04-23 12:29:43 +00:00
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
setFlags();
|
2002-11-13 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *POSIXFilesystemNode::getChild(const Common::String &n) const {
|
2008-09-03 14:55:19 +00:00
|
|
|
assert(!_path.empty());
|
2002-11-13 17:16:18 +00:00
|
|
|
assert(_isDirectory);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
// Make sure the string contains no slashes
|
2008-09-11 09:25:13 +00:00
|
|
|
assert(!n.contains('/'));
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
// We assume here that _path is already normalized (hence don't bother to call
|
2008-09-03 14:55:19 +00:00
|
|
|
// Common::normalizePath on the final path).
|
2008-08-03 18:29:37 +00:00
|
|
|
Common::String newPath(_path);
|
2008-09-17 18:26:44 +00:00
|
|
|
if (_path.lastChar() != '/')
|
2008-09-03 14:55:19 +00:00
|
|
|
newPath += '/';
|
2007-05-03 02:39:33 +00:00
|
|
|
newPath += n;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
return makeNode(newPath);
|
2007-05-03 02:39:33 +00:00
|
|
|
}
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2007-06-17 17:17:38 +00:00
|
|
|
bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
2007-05-03 02:39:33 +00:00
|
|
|
assert(_isDirectory);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-08-27 18:38:06 +00:00
|
|
|
#ifdef __OS2__
|
2008-09-02 15:19:31 +00:00
|
|
|
if (_path == "/") {
|
|
|
|
// Special case for the root dir: List all DOS drives
|
|
|
|
ULONG ulDrvNum;
|
|
|
|
ULONG ulDrvMap;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
DosQueryCurrentDisk(&ulDrvNum, &ulDrvMap);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
for (int i = 0; i < 26; i++) {
|
|
|
|
if (ulDrvMap & 1) {
|
2008-09-17 18:26:44 +00:00
|
|
|
char drive_root[] = "A:/";
|
2008-09-05 20:42:41 +00:00
|
|
|
drive_root[0] += i;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-05 20:42:41 +00:00
|
|
|
POSIXFilesystemNode *entry = new POSIXFilesystemNode();
|
|
|
|
entry->_isDirectory = true;
|
|
|
|
entry->_isValid = true;
|
|
|
|
entry->_path = drive_root;
|
2008-09-17 18:26:44 +00:00
|
|
|
entry->_displayName = "[" + Common::String(drive_root, 2) + "]";
|
2008-09-05 20:42:41 +00:00
|
|
|
myList.push_back(entry);
|
2008-09-02 15:19:31 +00:00
|
|
|
}
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
ulDrvMap >>= 1;
|
|
|
|
}
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-08-27 18:38:06 +00:00
|
|
|
#endif
|
2018-03-28 22:58:39 -05:00
|
|
|
#ifdef PSP2
|
|
|
|
if (_path == "/") {
|
|
|
|
POSIXFilesystemNode *entry1 = new POSIXFilesystemNode("ux0:");
|
|
|
|
myList.push_back(entry1);
|
|
|
|
POSIXFilesystemNode *entry2 = new POSIXFilesystemNode("uma0:");
|
|
|
|
myList.push_back(entry2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-27 18:38:06 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
DIR *dirp = opendir(_path.c_str());
|
2002-11-13 17:16:18 +00:00
|
|
|
struct dirent *dp;
|
2002-12-27 00:13:51 +00:00
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
if (dirp == NULL)
|
2006-05-03 20:43:26 +00:00
|
|
|
return false;
|
2004-02-01 01:31:50 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
// loop over dir entries using readdir
|
2002-11-13 17:16:18 +00:00
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
2007-06-17 17:17:38 +00:00
|
|
|
// Skip 'invisible' files if necessary
|
2007-06-20 00:28:04 +00:00
|
|
|
if (dp->d_name[0] == '.' && !hidden) {
|
2002-11-14 14:42:04 +00:00
|
|
|
continue;
|
2007-06-20 00:28:04 +00:00
|
|
|
}
|
|
|
|
// Skip '.' and '..' to avoid cycles
|
2007-09-18 20:16:33 +00:00
|
|
|
if ((dp->d_name[0] == '.' && dp->d_name[1] == 0) || (dp->d_name[0] == '.' && dp->d_name[1] == '.')) {
|
2002-11-14 14:42:04 +00:00
|
|
|
continue;
|
2007-06-20 00:28:04 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
// Start with a clone of this node, with the correct path set
|
|
|
|
POSIXFilesystemNode entry(*this);
|
|
|
|
entry._displayName = dp->d_name;
|
2008-09-05 20:42:41 +00:00
|
|
|
if (_path.lastChar() != '/')
|
2008-09-03 14:55:19 +00:00
|
|
|
entry._path += '/';
|
|
|
|
entry._path += entry._displayName;
|
2002-11-15 17:05:50 +00:00
|
|
|
|
2006-06-03 14:09:04 +00:00
|
|
|
#if defined(SYSTEM_NOT_SUPPORTING_D_TYPE)
|
2007-05-03 02:39:33 +00:00
|
|
|
/* TODO: d_type is not part of POSIX, so it might not be supported
|
|
|
|
* on some of our targets. For those systems where it isn't supported,
|
|
|
|
* add this #elif case, which tries to use stat() instead.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* The d_type method is used to avoid costly recurrent stat() calls in big
|
|
|
|
* directories.
|
|
|
|
*/
|
|
|
|
entry.setFlags();
|
2006-04-03 21:18:24 +00:00
|
|
|
#else
|
2006-04-10 19:26:40 +00:00
|
|
|
if (dp->d_type == DT_UNKNOWN) {
|
|
|
|
// Fall back to stat()
|
2007-05-03 02:39:33 +00:00
|
|
|
entry.setFlags();
|
2006-04-04 23:52:56 +00:00
|
|
|
} else {
|
2006-04-10 19:26:40 +00:00
|
|
|
entry._isValid = (dp->d_type == DT_DIR) || (dp->d_type == DT_REG) || (dp->d_type == DT_LNK);
|
|
|
|
if (dp->d_type == DT_LNK) {
|
|
|
|
struct stat st;
|
2006-05-08 04:48:40 +00:00
|
|
|
if (stat(entry._path.c_str(), &st) == 0)
|
|
|
|
entry._isDirectory = S_ISDIR(st.st_mode);
|
|
|
|
else
|
|
|
|
entry._isDirectory = false;
|
2006-04-10 19:26:40 +00:00
|
|
|
} else {
|
|
|
|
entry._isDirectory = (dp->d_type == DT_DIR);
|
|
|
|
}
|
2006-04-04 23:52:56 +00:00
|
|
|
}
|
2003-11-03 22:20:51 +00:00
|
|
|
#endif
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2006-04-03 21:18:24 +00:00
|
|
|
// Skip files that are invalid for some reason (e.g. because we couldn't
|
|
|
|
// properly stat them).
|
|
|
|
if (!entry._isValid)
|
|
|
|
continue;
|
|
|
|
|
2002-11-19 01:36:47 +00:00
|
|
|
// Honor the chosen mode
|
2008-10-02 16:58:59 +00:00
|
|
|
if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
|
|
|
|
(mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory))
|
2002-11-19 01:36:47 +00:00
|
|
|
continue;
|
2002-11-14 13:46:35 +00:00
|
|
|
|
2006-05-03 11:13:21 +00:00
|
|
|
myList.push_back(new POSIXFilesystemNode(entry));
|
2002-11-13 17:16:18 +00:00
|
|
|
}
|
|
|
|
closedir(dirp);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2002-11-13 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *POSIXFilesystemNode::getParent() const {
|
2004-11-21 13:18:07 +00:00
|
|
|
if (_path == "/")
|
2008-09-02 15:19:31 +00:00
|
|
|
return 0; // The filesystem root has no parent
|
2004-11-21 13:18:07 +00:00
|
|
|
|
2008-09-05 20:42:41 +00:00
|
|
|
#ifdef __OS2__
|
2019-04-28 15:06:31 +01:00
|
|
|
if (_path.size() == 3 && _path.hasSuffix(":/"))
|
|
|
|
// This is a root directory of a drive
|
|
|
|
return makeNode("/"); // return a virtual root for a list of drives
|
2008-09-05 20:42:41 +00:00
|
|
|
#endif
|
2018-03-28 22:58:39 -05:00
|
|
|
#ifdef PSP2
|
|
|
|
if (_path.hasSuffix(":"))
|
|
|
|
return makeNode("/");
|
|
|
|
#endif
|
2008-09-05 20:42:41 +00:00
|
|
|
|
2004-11-21 13:18:07 +00:00
|
|
|
const char *start = _path.c_str();
|
2008-09-02 15:19:31 +00:00
|
|
|
const char *end = start + _path.size();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-02 15:19:31 +00:00
|
|
|
// Strip of the last component. We make use of the fact that at this
|
|
|
|
// point, _path is guaranteed to be normalized
|
2008-09-03 14:55:19 +00:00
|
|
|
while (end > start && *(end-1) != '/')
|
2008-09-02 15:19:31 +00:00
|
|
|
end--;
|
|
|
|
|
2008-09-03 14:55:19 +00:00
|
|
|
if (end == start) {
|
|
|
|
// This only happens if we were called with a relative path, for which
|
|
|
|
// there simply is no parent.
|
|
|
|
// TODO: We could also resolve this by assuming that the parent is the
|
|
|
|
// current working directory, and returning a node referring to that.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeNode(Common::String(start, end));
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *POSIXFilesystemNode::createReadStream() {
|
2011-05-03 10:33:03 +02:00
|
|
|
return StdioStream::makeFromPath(getPath(), false);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::WriteStream *POSIXFilesystemNode::createWriteStream() {
|
2011-05-03 10:33:03 +02:00
|
|
|
return StdioStream::makeFromPath(getPath(), true);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 08:22:40 +00:00
|
|
|
bool POSIXFilesystemNode::create(bool isDirectoryFlag) {
|
2016-05-25 16:32:22 +06:00
|
|
|
bool success;
|
|
|
|
|
2017-01-12 08:22:40 +00:00
|
|
|
if (isDirectoryFlag) {
|
2016-05-25 16:32:22 +06:00
|
|
|
success = mkdir(_path.c_str(), 0755) == 0;
|
|
|
|
} else {
|
2016-08-30 20:35:02 +02:00
|
|
|
int fd = open(_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
|
|
|
success = fd >= 0;
|
|
|
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
close(fd);
|
|
|
|
}
|
2016-05-25 16:32:22 +06:00
|
|
|
}
|
|
|
|
|
2016-10-09 15:02:02 +02:00
|
|
|
if (success) {
|
2016-05-25 16:32:22 +06:00
|
|
|
setFlags();
|
|
|
|
if (_isValid) {
|
2017-01-12 08:22:40 +00:00
|
|
|
if (_isDirectory != isDirectoryFlag) warning("failed to create %s: got %s", isDirectoryFlag ? "directory" : "file", _isDirectory ? "directory" : "file");
|
|
|
|
return _isDirectory == isDirectoryFlag;
|
2016-05-25 16:32:22 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
warning("POSIXFilesystemNode: %s() was a success, but stat indicates there is no such %s",
|
2017-01-12 08:22:40 +00:00
|
|
|
isDirectoryFlag ? "mkdir" : "creat", isDirectoryFlag ? "directory" : "file");
|
2016-05-25 16:32:22 +06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:09:29 +01:00
|
|
|
namespace Posix {
|
|
|
|
|
|
|
|
bool assureDirectoryExists(const Common::String &dir, const char *prefix) {
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
// Check whether the prefix exists if one is supplied.
|
|
|
|
if (prefix) {
|
|
|
|
if (stat(prefix, &sb) != 0) {
|
|
|
|
return false;
|
|
|
|
} else if (!S_ISDIR(sb.st_mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain absolute path.
|
|
|
|
Common::String path;
|
|
|
|
if (prefix) {
|
|
|
|
path = prefix;
|
|
|
|
path += '/';
|
|
|
|
path += dir;
|
|
|
|
} else {
|
|
|
|
path = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = Common::normalizePath(path, '/');
|
|
|
|
|
|
|
|
const Common::String::iterator end = path.end();
|
|
|
|
Common::String::iterator cur = path.begin();
|
|
|
|
if (*cur == '/')
|
|
|
|
++cur;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (cur + 1 != end) {
|
|
|
|
if (*cur != '/') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is kind of ugly and against the purpose of Common::String to
|
|
|
|
// insert 0s inside, but this is just for a local string and
|
|
|
|
// simplifies the code a lot.
|
|
|
|
*cur = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mkdir(path.c_str(), 0755) != 0) {
|
|
|
|
if (errno == EEXIST) {
|
|
|
|
if (stat(path.c_str(), &sb) != 0) {
|
|
|
|
return false;
|
|
|
|
} else if (!S_ISDIR(sb.st_mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*cur = '/';
|
|
|
|
} while (cur++ != end);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Posix
|
|
|
|
|
2011-05-05 15:38:54 +02:00
|
|
|
#endif //#if defined(POSIX)
|