MCPcopy Create free account
hub / github.com/Tencent/phxsql / SetFilePos

Method SetFilePos

phxbinlogsvr/core/storage/storage.cpp:94–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94int Storage::SetFilePos(const string &path, const size_t &offset, const MODE &mode, bool trunc) {
95 if (mode_ != mode) {
96 ColorLogWarning("%s not read mode file", __func__);
97 return FILE_FORBIDDEN;
98 }
99
100 if (path_ != path) {
101 int ret = ReOpen(path);
102 if (ret)
103 return ret;
104 }
105
106 off_t ret = lseek(fd_, offset, SEEK_SET);
107 if (ret == (off_t) - 1) {
108 return FILE_FAIL;
109 }
110 if (trunc) {
111 int ret = ftruncate(fd_, offset);
112 if (ret) {
113 ColorLogError("%s trunc file fail, path %s(%d) offset %u ret %d error %s", __func__, path.c_str(),
114 fd_, offset, ret, strerror(errno));
115 return FILE_FAIL;
116 }
117 struct stat sbuf;
118 memset(&sbuf, 0, sizeof(sbuf));
119 stat((data_dir_ + path).c_str(), &sbuf);
120 phxsql::LogVerbose("%s set file pos %s offset %u, size after trunc %u", __func__, (data_dir_ + path).c_str(),
121 GetOffSet(), sbuf.st_size);
122 } else {
123 phxsql::LogVerbose("%s set file pos %s offset %u", __func__, path.c_str(), GetOffSet());
124 }
125 return OK;
126}
127
128int Storage::CloseDB() {
129 if (fd_ >= 0) {

Callers

nothing calls this directly

Calls 4

ColorLogWarningFunction · 0.85
ColorLogErrorFunction · 0.85
LogVerboseFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected