Skip to content

Commit

Permalink
refactor: replace pstd/env with std::filesystem (OpenAtomFoundation#1470
Browse files Browse the repository at this point in the history
)
  • Loading branch information
4kangjc authored Jun 6, 2023
1 parent 5590cd9 commit baa8977
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 215 deletions.
13 changes: 6 additions & 7 deletions src/pika_stable_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ bool StableLog::PurgeFiles(uint32_t to, bool manual) {
}

// Do delete
pstd::Status s = pstd::DeleteFile(log_path_ + it->second);
if (s.ok()) {
if (pstd::DeleteFile(log_path_ + it->second)) {
++delete_num;
--remain_expire_num;
} else {
LOG(WARNING) << log_path_ << " Purge log file : " << (it->second) << " failed! error:" << s.ToString();
LOG(WARNING) << log_path_ << " Purge log file : " << (it->second) << " failed! error: delete file failed";
}
} else {
// Break when face the first one not satisfied
Expand Down Expand Up @@ -209,11 +208,11 @@ Status StableLog::PurgeFileAfter(uint32_t filenum) {
for (auto& it : binlogs) {
if (it.first > filenum) {
// Do delete
Status s = pstd::DeleteFile(log_path_ + it.second);
if (!s.ok()) {
return s;
auto filename = log_path_ + it.second;
if (!pstd::DeleteFile(filename)) {
return Status::IOError("pstd::DeleteFile faield, filename = " + filename);
}
LOG(WARNING) << "Delete file " << log_path_ + it.second;
LOG(WARNING) << "Delete file " << filename;
}
}
return Status::OK();
Expand Down
19 changes: 13 additions & 6 deletions src/pstd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ target_include_directories(pstd
${INSTALL_INCLUDEDIR}
)

target_link_libraries(pstd
PUBLIC ${GLOG_LIBRARY}
${GFLAGS_LIBRARY}
${FMT_LIBRARY}
${LIBUNWIND_LIBRARY}
)
set(PSTD_DEP_LIBS ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} ${FMT_LIBRARY} ${LIBUNWIND_LIBRARY})

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION LESS 9)
list(APPEND PSTD_DEP_LIBS stdc++fs)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION LESS 9)
list(APPEND PSTD_DEP_LIBS c++fs)
endif()
endif()

target_link_libraries(pstd PUBLIC ${PSTD_DEP_LIBS})
7 changes: 2 additions & 5 deletions src/pstd/include/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ uint64_t Du(const std::string& filename);
*/
bool FileExists(const std::string& path);

Status DeleteFile(const std::string& fname);
bool DeleteFile(const std::string& fname);

int RenameFile(const std::string& oldname, const std::string& newname);

Expand All @@ -57,11 +57,8 @@ class FileLock : public pstd::noncopyable {
std::string name_;
};

Status LockFile(const std::string& f, FileLock** l);
Status UnlockFile(FileLock* l);

int GetChildren(const std::string& dir, std::vector<std::string>& result);
bool GetDescendant(const std::string& dir, std::vector<std::string>& result);
void GetDescendant(const std::string& dir, std::vector<std::string>& result);

uint64_t NowMicros();
void SleepForMicroseconds(int micros);
Expand Down
Loading

0 comments on commit baa8977

Please sign in to comment.