Esempio n. 1
0
	static bool make_directory_raw(const std::string &path)
	{
		// allow multiple tries (to build parent directories)
		while (true) {
			if (mkdir(path.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
				switch (errno) {
				case EEXIST:
					{
						struct stat statinfo;
						stat(path.c_str(), &statinfo);
						return S_ISDIR(statinfo.st_mode);
					}
				case ENOENT:
					{
						size_t pos = path.rfind('/');
						if (pos != std::string::npos) {
							const std::string dirname = path.substr(0, pos-1);
							if (dirname.empty() || !make_directory_raw(dirname)) {
								return false;
							}
						} else
							return false;
					}
				default: return false;
				}
			} else {
				return true;
			}
		}
	}
Esempio n. 2
0
	static bool make_directory_raw(std::wstring path)
	{
		// allow multiple tries (to build parent directories)
		while (true) {
			if (!CreateDirectoryW(path.c_str(), 0)) {
				DWORD err = GetLastError();
				if (err == ERROR_ALREADY_EXISTS) {
					DWORD attrs = GetFileAttributesW(path.c_str());
					return ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
				} else if (err == ERROR_PATH_NOT_FOUND) {
					if (!PathRemoveFileSpecW(&path[0]))
						return false;
					path.resize(wcslen(&path[0]));
					if (!path.empty() || !make_directory_raw(path)) {
						return false;
					}
				} else {
					Output("error while attempting to create directory '%s'\n", transcode_utf16_to_utf8(path).c_str());
					return false;
				}
			}
		}
	}
Esempio n. 3
0
	bool FileSourceFS::MakeDirectory(const std::string &path)
	{
		const std::string fullpath = JoinPathBelow(GetRoot(), path);
		return make_directory_raw(fullpath);
	}
Esempio n. 4
0
	bool FileSourceFS::MakeDirectory(const std::string &path)
	{
		const std::string fullpath = JoinPathBelow(GetRoot(), path);
		const std::wstring wfullpath = transcode_utf8_to_utf16(fullpath);
		return make_directory_raw(wfullpath);
	}