You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
Relocating everything in the repo s.t. it can be merged into
the columnstore repo.
This commit is contained in:
92
storage-manager/src/StatTask.cpp
Normal file
92
storage-manager/src/StatTask.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/* Copyright (C) 2019 MariaDB Corporation
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
|
||||
#include "StatTask.h"
|
||||
#include "messageFormat.h"
|
||||
#include "SMLogging.h"
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace storagemanager
|
||||
{
|
||||
|
||||
StatTask::StatTask(int sock, uint len) : PosixTask(sock, len)
|
||||
{
|
||||
}
|
||||
|
||||
StatTask::~StatTask()
|
||||
{
|
||||
}
|
||||
|
||||
#define check_error(msg, ret) \
|
||||
if (!success) \
|
||||
{ \
|
||||
handleError(msg, errno); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
bool StatTask::run()
|
||||
{
|
||||
SMLogging* logger = SMLogging::get();
|
||||
bool success;
|
||||
uint8_t buf[1024] = {0};
|
||||
|
||||
if (getLength() > 1023) {
|
||||
handleError("StatTask read", ENAMETOOLONG);
|
||||
return true;
|
||||
}
|
||||
|
||||
success = read(buf, getLength());
|
||||
check_error("StatTask read", false);
|
||||
stat_cmd *cmd = (stat_cmd *) buf;
|
||||
sm_response *resp = (sm_response *) buf;
|
||||
|
||||
#ifdef SM_TRACE
|
||||
logger->log(LOG_DEBUG,"stat %s.",cmd->filename);
|
||||
#endif
|
||||
int err;
|
||||
try
|
||||
{
|
||||
err = ioc->stat(cmd->filename, (struct stat *) resp->payload);
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
logger->log(LOG_DEBUG, "StatTask: caught '%s'", e.what());
|
||||
errno = EIO;
|
||||
err = -1;
|
||||
}
|
||||
|
||||
resp->returnCode = err;
|
||||
uint payloadLen;
|
||||
if (!err)
|
||||
payloadLen = sizeof(struct stat);
|
||||
else {
|
||||
payloadLen = 4;
|
||||
*((int32_t *) resp->payload) = errno;
|
||||
}
|
||||
success = write(*resp, payloadLen);
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user