Пример #1
0
void FileImpl::handleLastErrorImpl(const std::string& path)
{
    switch (errno)
    {
    case EIO:
        throw IOException(path);
    case EPERM:
        throw FileAccessDeniedException("insufficient permissions", path);
    case EACCES:
        throw FileAccessDeniedException(path);
    case ENOENT:
        throw FileNotFoundException(path);
    case ENOTDIR:
        throw OpenFileException("not a directory", path);
    case EISDIR:
        throw OpenFileException("not a file", path);
    case EROFS:
        throw FileReadOnlyException(path);
    case EEXIST:
        throw FileExistsException(path);
    case ENOSPC:
        throw FileException("no space left on device", path);
    case ENOTEMPTY:
        throw FileException("directory not empty", path);
    case ENAMETOOLONG:
        throw PathSyntaxException(path);
    case ENFILE:
    case EMFILE:
        throw FileException("too many open files", path);
    default:
        throw FileException(std::strerror(errno), path);
    }
}
Пример #2
0
void FileImpl::renameToImpl(const std::string& path)
{
	poco_assert (!_path.empty());

	POCO_DESCRIPTOR_STRING(oldNameDsc, _path);
	POCO_DESCRIPTOR_STRING(newNameDsc, path);

	int res;
	if ((res = lib$rename_file(&oldNameDsc, &newNameDsc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) != 1)
	{
		switch (res & 0x0FFFFFFF)
		{
		case RMS$_FNF: 
			throw FileNotFoundException(_path);
		case RMS$_DEV:
		case RMS$_DNF:
			throw PathNotFoundException(_path);
		case RMS$_SYN:
			throw PathSyntaxException(path);
		case RMS$_RMV:
			throw FileAccessDeniedException(_path);
		case RMS$_PRV:
			throw FileAccessDeniedException("insufficient privileges", _path);		
		default:
			throw FileException(path);
		}
	}
}
Пример #3
0
void Path::parseWindows(const std::string& path)
{
	clear();

	std::string::const_iterator it  = path.begin();
	std::string::const_iterator end = path.end();

	if (it != end)
	{
		if (*it == '\\' || *it == '/') { _absolute = true; ++it; }
		if (_absolute && it != end && (*it == '\\' || *it == '/')) // UNC
		{
			++it;
			while (it != end && *it != '\\' && *it != '/') _node += *it++;
			if (it != end) ++it;
		}
		else if (it != end)
		{
			char d = *it++;
			if (it != end && *it == ':') // drive letter
			{
				if (_absolute || !((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))) throw PathSyntaxException(path);
				_absolute = true;
				_device += d;
				++it;
				if (it == end || (*it != '\\' && *it != '/')) throw PathSyntaxException(path);
				++it;
			}
			else --it;
		}
		while (it != end)
		{
			std::string name;
			while (it != end && *it != '\\' && *it != '/') name += *it++;
			if (it != end)
				pushDirectory(name);
			else
				_name = name;
			if (it != end) ++it;
		}
	}
	if (!_node.empty() && _dirs.empty() && !_name.empty())
		makeDirectory();
}
Пример #4
0
void FileImpl::handleLastErrorImpl(const std::string& path)
{
	DWORD err = GetLastError();
	switch (err)
	{
	case ERROR_FILE_NOT_FOUND:
		throw FileNotFoundException(path, err);
	case ERROR_PATH_NOT_FOUND:
	case ERROR_BAD_NETPATH:
	case ERROR_CANT_RESOLVE_FILENAME:
	case ERROR_INVALID_DRIVE:
		throw PathNotFoundException(path, err);
	case ERROR_ACCESS_DENIED:
		throw FileAccessDeniedException(path, err);
	case ERROR_ALREADY_EXISTS:
	case ERROR_FILE_EXISTS:
		throw FileExistsException(path, err);
	case ERROR_INVALID_NAME:
	case ERROR_DIRECTORY:
	case ERROR_FILENAME_EXCED_RANGE:
	case ERROR_BAD_PATHNAME:
		throw PathSyntaxException(path, err);
	case ERROR_FILE_READ_ONLY:
		throw FileReadOnlyException(path, err);
	case ERROR_CANNOT_MAKE:
		throw CreateFileException(path, err);
	case ERROR_DIR_NOT_EMPTY:
		throw FileException("directory not empty", path, err);
	case ERROR_WRITE_FAULT:
		throw WriteFileException(path, err);
	case ERROR_READ_FAULT:
		throw ReadFileException(path, err);
	case ERROR_SHARING_VIOLATION:
		throw FileException("sharing violation", path, err);
	case ERROR_LOCK_VIOLATION:
		throw FileException("lock violation", path, err);
	case ERROR_HANDLE_EOF:
		throw ReadFileException("EOF reached", path, err);
	case ERROR_HANDLE_DISK_FULL:
	case ERROR_DISK_FULL:
		throw WriteFileException("disk is full", path, err);
	case ERROR_NEGATIVE_SEEK:
		throw FileException("negative seek", path, err);
	default:
		throw FileException(path, err);
	}
}
Пример #5
0
void FileImpl::handleLastErrorImpl(const std::string& path)
{
	switch (errno)
	{
	case EIO:
		throw IOException(path, errno);
	case EPERM:
		throw FileAccessDeniedException("insufficient permissions", path, errno);
	case EACCES:
		throw FileAccessDeniedException(path, errno);
	case ENOENT:
		throw FileNotFoundException(path, errno);
	case ENOTDIR:
		throw OpenFileException("not a directory", path, errno);
	case EISDIR:
		throw OpenFileException("not a file", path, errno);
	case EROFS:
		throw FileReadOnlyException(path, errno);
	case EEXIST:
		throw FileExistsException(path, errno);
	case ENOSPC:
		throw FileException("no space left on device", path, errno);
	case EDQUOT:
		throw FileException("disk quota exceeded", path, errno);
#if !defined(_AIX)
	case ENOTEMPTY:
		throw DirectoryNotEmptyException(path, errno);
#endif
	case ENAMETOOLONG:
		throw PathSyntaxException(path, errno);
	case ENFILE:
	case EMFILE:
		throw FileException("too many open files", path, errno);
	default:
		throw FileException(Error::getMessage(errno), path, errno);
	}
}
Пример #6
0
void Path::parseVMS(const std::string& path)
{
	clear();

	std::string::const_iterator it  = path.begin();
	std::string::const_iterator end = path.end();

	if (it != end)
	{
		std::string name;
		while (it != end && *it != ':' && *it != '[' && *it != ';') name += *it++;
		if (it != end)
		{
			if (*it == ':')
			{
				++it;
				if (it != end && *it == ':')
				{
					_node = name;
					++it;
				}
				else _device = name;
				_absolute = true;
				name.clear();
			}
			if (it != end)
			{
				if (_device.empty() && *it != '[')
				{
					while (it != end && *it != ':' && *it != ';') name += *it++;
					if (it != end)
					{
						if (*it == ':')
						{
							_device = name;
							_absolute = true;
							name.clear();
							++it;
						}
					}
				}
			}			
			if (name.empty())
			{
				if (it != end && *it == '[')
				{
					++it;
					if (it != end)
					{
						_absolute = true;
						if (*it == '.')
							{ _absolute = false; ++it; }
						else if (*it == ']' || *it == '-')
							_absolute = false;
						while (it != end && *it != ']')
						{
							name.clear();
							if (*it == '-')
								name = "-";
							else
								while (it != end && *it != '.' && *it != ']') name += *it++;
							if (!name.empty())
							{
								if (name == "-")
								{
									if (_dirs.empty() || _dirs.back() == "..")
										_dirs.push_back("..");
									else 
										_dirs.pop_back();
								}
								else _dirs.push_back(name);
							}
							if (it != end && *it != ']') ++it;
						}
						if (it == end) throw PathSyntaxException(path);
						++it;
						if (it != end && *it == '[')
						{
							if (!_absolute) throw PathSyntaxException(path);
							++it;
							if (it != end && *it == '.') throw PathSyntaxException(path);
							int d = int(_dirs.size());
							while (it != end && *it != ']')
							{
								name.clear();
								if (*it == '-')
									name = "-";
								else
									while (it != end && *it != '.' && *it != ']') name += *it++;
								if (!name.empty())
								{
									if (name == "-")
									{
										if (_dirs.size() > d)
											_dirs.pop_back();
									}
									else _dirs.push_back(name);
								}
								if (it != end && *it != ']') ++it;
							}
							if (it == end) throw PathSyntaxException(path);
							++it;
						}
					}
					_name.clear();
				}
				while (it != end && *it != ';') _name += *it++;
			}
			else _name = name;
			if (it != end && *it == ';')
			{
				++it;
				while (it != end) _version += *it++;
			}
		}
		else _name = name;
	}
}