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); } }
void MetaDataStore::add(const ObjectId& parent, const std::string& name, DirectoryEntryPtr dentry) { LOG_TRACE(parent << ", dentry uuid " << dentry->object_id() << " name " << name); const yt::UUID p(parent.str()); const boost::optional<DirectoryEntry> oldval; try { harakoon_.test_and_set(p, name, *dentry, oldval); } catch (HierarchicalArakoon::PreconditionFailedException) { throw FileExistsException("Metadata entry already exists", name.c_str(), EEXIST); } FrontendPath path(find_path(parent)); path /= name; maybe_add_to_cache_(path, dentry); }
void MetaDataStore::add(const FrontendPath& path, DirectoryEntryPtr dentry) { LOG_TRACE(path << ", dentry uuid " << dentry->object_id()); const ArakoonPath p(path.string()); const boost::optional<DirectoryEntry> oldval; try { harakoon_.test_and_set(p, *dentry, oldval); } catch (HierarchicalArakoon::PreconditionFailedException&) { // Someone else must've beaten us to adding an entry under 'path'. #ifndef NDEBUG walk(FrontendPath("/"), [](const FrontendPath& fp, const DirectoryEntryPtr& /* dep */) { LOG_DEBUG(fp); }); #endif throw FileExistsException("Metadata entry already exists", path.string().c_str(), EEXIST); } maybe_add_to_cache_(path, dentry); }
void SerialChannelImpl::handleError(const std::string& name) { std::string errorText; DWORD error = GetLastError(); switch (error) { case ERROR_FILE_NOT_FOUND: throw FileNotFoundException(name, getErrorText(errorText)); case ERROR_ACCESS_DENIED: throw FileAccessDeniedException(name, getErrorText(errorText)); case ERROR_ALREADY_EXISTS: case ERROR_FILE_EXISTS: throw FileExistsException(name, getErrorText(errorText)); case ERROR_FILE_READ_ONLY: throw FileReadOnlyException(name, getErrorText(errorText)); case ERROR_CANNOT_MAKE: case ERROR_INVALID_NAME: case ERROR_FILENAME_EXCED_RANGE: throw CreateFileException(name, getErrorText(errorText)); case ERROR_BROKEN_PIPE: case ERROR_INVALID_USER_BUFFER: case ERROR_INSUFFICIENT_BUFFER: throw IOException(name, getErrorText(errorText)); case ERROR_NOT_ENOUGH_MEMORY: throw OutOfMemoryException(name, getErrorText(errorText)); case ERROR_HANDLE_EOF: break; default: throw FileException(name, getErrorText(errorText)); } }
void mkDir( const std::string &directory ) { #ifdef WINXX throw FileUtilsException( "mkDir: On windows not yet supported (directory: " + directory + ")!" ); #else struct stat st; if ( stat( directory.c_str() , &st ) == 0 && S_ISDIR( st.st_mode ) ) throw FileExistsException( "mkDir: Directory \"" + directory + "\" already exists!" ); int check = mkdir( directory.c_str() , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ); if ( check != 0 ) throw FileUtilsException( "mkDir: Cannot create directory \"" + directory + "\"!" ); #endif }
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); } }
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); } }